Skip to content
Snippets Groups Projects
Commit 9a38c687 authored by Maël Madon's avatar Maël Madon
Browse files

gave a name to main script

parent d1d79384
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse, json, re import argparse, json, re, os.path, sys
from user_session_builder import User from user_session_builder import User
from workload import SwfField, Job from workload import SwfField, Job
def main(input_swf, output_folder, delim_approach, delim_threshold, def swf2sessions(input_swf, output_folder, delim_approach, delim_threshold,
dynamic_reduction, build_graph_rep, quiet): dynamic_reduction, build_graph_rep, quiet):
users = {} users = {}
# if not os.path.exists(input_swf):
# raise FileExistsError(f"Input file '{input_swf}' does not exist")
if not os.path.exists(output_folder):
raise FileExistsError(f"Output folder '{output_folder}' does not exist")
# Read SWF # Read SWF
element = '([-+]?\d+(?:\.\d+)?)' element = '([-+]?\d+(?:\.\d+)?)'
r = re.compile('\s*' + (element + '\s+') * 17 + element + '\s*') r = re.compile('\s*' + (element + '\s+') * 17 + element + '\s*')
...@@ -56,64 +62,64 @@ def main(input_swf, output_folder, delim_approach, delim_threshold, ...@@ -56,64 +62,64 @@ def main(input_swf, output_folder, delim_approach, delim_threshold,
print("Number of sessions: ", sum([len(u.sessions) for u in users.values()])) print("Number of sessions: ", sum([len(u.sessions) for u in users.values()]))
print(f"The output files have been stored in the folder {output_folder}") print(f"The output files have been stored in the folder {output_folder}")
if __name__== "__main__":
parser = argparse.ArgumentParser(description='TODO') parser = argparse.ArgumentParser(description='TODO')
parser.add_argument('input_swf', parser.add_argument('input_swf',
type=argparse.FileType('r'), type=argparse.FileType('r'),
help='The input SWF file') help='The input SWF file')
parser.add_argument('output_folder', parser.add_argument('output_folder',
type=str, type=str,
help='The folder that will store the output files') help='The folder that will store the output files')
group = parser.add_mutually_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-a', group.add_argument('-a',
'--arrival', '--arrival',
help='Arrival delimitation approach', help='Arrival delimitation approach',
action="store_true") action="store_true")
group.add_argument('-l', group.add_argument('-l',
'--last', '--last',
help='Last delimitation approach', help='Last delimitation approach',
action="store_true") action="store_true")
group.add_argument('-m', group.add_argument('-m',
'--max', '--max',
help='Max delimitation approach', help='Max delimitation approach',
action="store_true") action="store_true")
parser.add_argument( parser.add_argument(
'-t', '-t',
'--threshold', '--threshold',
type=int, type=int,
help= help=
'Unit: minutes. The threshold (on think-time or inter-arrival time, depending on the delimiation approach) above which a job will be considered to be in a new session.' 'Unit: minutes. The threshold (on think-time or inter-arrival time, depending on the delimiation approach) above which a job will be considered to be in a new session.'
) )
parser.add_argument( parser.add_argument(
'--no_dynamic_reduction', '--no_dynamic_reduction',
action="store_true", action="store_true",
help= help=
'Unless this option is specified, during the construction of the graph the algorithm dynamically avoids to add an edge between two nodes if a path already exists.' 'Unless this option is specified, during the construction of the graph the algorithm dynamically avoids to add an edge between two nodes if a path already exists.'
) )
parser.add_argument( parser.add_argument(
'--graph', '--graph',
action="store_true", action="store_true",
help= help=
"Build a graphical representation of each session graph and save it in the output folder as a gml file" "Build a graphical representation of each session graph and save it in the output folder as a gml file"
) )
parser.add_argument("-q", "--quiet", action="store_true") parser.add_argument("-q", "--quiet", action="store_true")
args = parser.parse_args() args = parser.parse_args()
if args.last: if args.last:
delim = 'last' delim = 'last'
elif args.max: elif args.max:
delim = 'max' delim = 'max'
else: else:
delim = 'arrival' delim = 'arrival'
main(input_swf=args.input_swf, swf2sessions(input_swf=args.input_swf,
output_folder=args.output_folder, output_folder=args.output_folder,
delim_approach=delim, delim_approach=delim,
delim_threshold=args.threshold, delim_threshold=args.threshold,
dynamic_reduction=not (args.no_dynamic_reduction), dynamic_reduction=not (args.no_dynamic_reduction),
build_graph_rep=args.graph, build_graph_rep=args.graph,
quiet=args.quiet) quiet=args.quiet)
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment