-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueGenerationScript.py
More file actions
executable file
·90 lines (74 loc) · 2.2 KB
/
queueGenerationScript.py
File metadata and controls
executable file
·90 lines (74 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python
#============================================================#
# Python 2.7.x
#============================================================#
#General imports.
import sys #For passed in arguments.
import os
import csv
import random
directory = "input";
task_suffix = ".task";
queue_suffix = ".queue";
#============================================================#
def write_shuffled_tasks(file, taskCountsMap):
#{
workQueue = [];
for key, value in taskCountsMap.iteritems():
#{
entry = [key, "stub"];
workQueue.extend([entry]*value);
#}
#Randomize the work order.
random.shuffle(workQueue);
with open(file, 'wb') as csvfile:
#{
writer = csv.writer(csvfile, delimiter='\t');
writer.writerows(workQueue);
#}
#}
#============================================================#
#============================================================#
if (len(sys.argv)) < 4:
#{
print sys.argv[0] + " <queue name> <task count> <task>:<percent> ...";
exit(0);
#}
#Create input directory.
if not os.path.exists("input"):
#{
os.makedirs("input");
#}
queue_name = sys.argv[1];
task_count = int(sys.argv[2]);
print "Queue name: " + queue_name;
print "Task count: " + str(task_count);
print "Task mix breakdown:";
taskCountsMap = {};
percentage = 0;
for i in range (3, len(sys.argv)):
#{
tup = sys.argv[i].split(":");
#Record exact task count to generate.
taskCount = int(tup[1])*task_count/100;
taskCountsMap[tup[0]] = taskCount;
#Print count for each task.
print "\t " + tup[0] + ": " + str(taskCount) + " (" + tup[1] + "%)";
#check for task existence.
if os.path.isfile(directory + "/" + tup[0] + task_suffix) == False:
#{
print "Error: specified task '" + tup[0] +"' not found in directory '" + directory + "'..."
exit(0);
#}
#Must add to 100%...
percentage = percentage + int(tup[1]);
#}
if percentage != 100:
#{
print "Error: instruction mix must add to 100%...";
exit(0);
#}
print "Generating queue..."
file = "{}/{}{}".format(directory, queue_name, queue_suffix);
write_shuffled_tasks(file, taskCountsMap);
#============================================================#