I am trying to do a graph traversal where i want to list only the recursive path
My traversal has a variable depth of 1..10, which will find the followings paths:
1. start - decide - execute1 - end
2. start - decide - execute2 - decide - execute1 - end
3. start - execute3 - end
With the below query:
FOR v, e, p IN 1..10 OUTBOUND 'Node/start_0' Path
FILTER v.name == "end"
RETURN CONCAT_SEPARATOR(' - ', p.vertices[*].name)
Now i want to list only the path that has recursion or loop on it, in this example i want to get only the path 2. start - decide - execute2 - decide - execute1 - end since it goes through decide - execute2 - decide.
I know we can avoid such loop Scenario by setting uniqueVertices: 'path' but how to get only the scenario that has loop in it
Related
That's my matrix:
jobs:
check-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
And I have this current conditional (that's working):
if: matrix.python-version == 3.6
How can I replace 3.6 by the first item of my matrix? I mean, how to tell in yaml:
if: matrix.python-version == "the_first_item_from_matrix.python-version"
And no, matrix.python-version[0] (or [1], I don't know how it's indexed) won't work.
The reasoning here is: in some point I will drop 3.6 support and I don't want to remember to remove any 3.6 hardcoded in my workflow.
I propose a simple workaround using the strategy.job-index property. According to the documentation, this property is defined as follows:
The index of the current job in the matrix. Note: This number is a zero-based number. The first job's index in the matrix is 0.
You can use this property to ensure that a step is only executed for the first job in the matrix.
Here is a minimal workflow to demonstrate the idea:
name: demo
on:
push:
jobs:
demo:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.10']
runs-on: ubuntu-latest
steps:
- if: strategy.job-index == 0
run: echo '3.7' && exit 1
- if: strategy.job-index == 1
run: echo '3.10' && exit 1
Here are screenshots to show the result:
Sadly this workaround will get more complicated once we start to work with a matrix that has more than one dimension.
I have this list and would like for all of the timestamps to have the same format (... = more elements):
timestampList = [...
"8:36 - Appointment1",
"9:21 - Appointment2",
"10:01 - Appointment3",
"11:52 - Appointment4",
"12:18 - Appointment5" ...]
Is there an easy way to make sure all timestamps in the list have the same format(HH:MM)? Is there perhaps a module that makes this possible? I have tried to resolve the problem but couldn't find a way of doing it. I want the list to look like this:
timestampList = [...
"08:36 - Appointment1",
"09:21 - Appointment2",
"10:01 - Appointment3",
"11:52 - Appointment4",
"12:18 - Appointment5" ...]
You can use re.sub and a lookahead regex from the beginning of the line. If we see that the timestamp starts with \d:, then prepend a "0":
>>> import re
>>> [re.sub(r"^(?=\d:)", "0", x) for x in timestamps]
['08:36 - Appointment1', '09:21 - Appointment2', '10:01 - Appointment3', '11:52 - Appointment4', '12:18 - Appointment5']
I have created two collections in ArangoDB, a document collection "Node" and an edge collection "Path". All my nodes have a name attribute and are connected by edges.
My traversal has a variable depth of 1..10, which will find the followings paths:
start - decide
start - decide - execute1
start - decide - execute2
start - decide - execute1 - error
start - decide - execute2 - end
start - decide - execute1 - execute2 - end
start - decide - execute1 - execute2 - error
start - decide - execute2 - execute3 - end
I tried below query to find paths that end with an end or error node:
FOR v, e, p IN 1..10 OUTBOUND 'Node/start_0' Path
OPTIONS { bfs: true}
FILTER (v.name == "end" OR v.name == "error")
RETURN CONCAT_SEPARATOR(' - ', p.vertices[*].name)
It gives me below 4 Results
[
start - decide - execute1 - error
start - decide - execute2 - end
start - decide - execute1 - execute2 - end
start - decide - execute1 - execute2 - error
start - decide - execute2 - execute3 - end
]
Here i want to do a additional pattern matching check, I want to list results that has particular sequence of vertex in them.
I want to list the result that has sequence decide execute1 execute2 in them
i.e., My result should be as given below:
[
start - decide - execute1 - execute2 - end
start - decide - execute1 - execute2 - error
]
I tried adding below filter condition to my query but it didnot work
FILTER LIKE(p.vertices[*].name, "%decide - execute1 - execute2%", true)
Can Someone help me on this
I believe this should work if you move the main query into a subquery, and then apply the filter afterwards, e.g. something like:
FOR path IN (
FOR v, e, p IN 1..10 OUTBOUND 'Node/start_0' Path
OPTIONS { bfs: true}
FILTER (v.name == "end" OR v.name == "error")
RETURN CONCAT_SEPARATOR(' - ', p.vertices[*].name)
)
FILTER LIKE(path, "%decide - execute1 - execute2%", true)
RETURN path
I want to rename all files in a directory by tkinter listbox.
Got stuck at this point:
files_list = os.listdir(root.foldername)
print(files_list)
gives me
['1.mp4', '10.mp4', '2.mp4', '3.mp4', '4.mp4', '5.mp4', '6.mp4', '7.mp4', '8.mp4', '9.mp4']
values = [listbox.get(idx) for idx in listbox.curselection()]<br>
And
inlist = (', '.join(values))<br>
print(inlist)
gives me
Lost - 1x01 - Pilot(1), Lost - 1x02 - Pilot(2), Lost - 1x03 - Tabula Rasa, Lost - 1x04 - Walkabout, Lost - 1x05 - White Rabbit, Lost - 1x06 - House Of The Rising Sun, Lost - 1x07 - The Moth, Lost - 1x08 - Confidence Man, Lost - 1x09 - Solitary, Lost - 1x10 - Raised By Another
Now I'm looking for a solution to use os.rename in order to rename the files 1.mp4 till 10.mp4.
Additionally Python for whatever reason does not come with a built-in way to have natural sorting, so it sorts 1.mp4 followed by 10.mp4.
Thank you very much in advance.
For natural sorting take a look at Sorting alphanumeric strings in Python.
Then loop through all files and rename them, eg.
for i in range(len(files_list)):
old_file_name = files_list[i]
new_file_name = values[i] + '.mp4'
os.rename(old_file_name, new_file_name)
For assistance in dealing with pathnames see os.path.
How can i split the given file into two different files results codes and warning codes.AS given below is single text file and I want to split it into two files as I had lot more file in such condition to split.
Result Codes:
0 - SYS_OK - "Ok"
1 - SYS_ERROR_E - "System Error"
1001 - MVE_SYS_E - "MTE System Error"
1002 - MVE_COMMAND_SYNTAX_ERROR_E - "Command Syntax is wrong"
Warning Codes:
0 - SYS_WARN_W - "System Warning"
100001 - MVE_SYS_W - "MVE System Warning"
200001 - SLEA_SYS_W - "SLEA System Warning"
200002 - SLEA_INCOMPLETE_SCRIPTED_OVERRIDE_COMMAND_W - "One or more of the entered scripted override commands has missing mandatory parameters"
300001 - L1_SYS_W - "L1 System Warning"
Well, on first glance, the distinction seems to be that "warnings" all contain the character sequence _W - and anything that doesn't is "results". Did you notice that?
awk '/_W -/{print >"warnings";next}{print >"results"}'
Here is a python solution:
I am assuming you are having the list of warning codes.
import re
warnings = open(r'warning-codes.txt');
warn_codes =[]
for line in warnings:
m = re.search(r'(\d+) .*',line);
if(m):
warn_codes.append(m.groups(1));
ow = open('output-warnings.txt','w')
ors = open('output-results.txt','w')
log_file = open(r'log.txt');
for line in log_file:
m = re.search(r'(\d+) .*',line);
if(m and (m.groups(1) in warn_codes)):
ow.write(line+'\n');
elif(m):
ors.write(line+'\n');
else:
print("none");
ow.close()
ors.close()