-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimportForComparison.py
executable file
·87 lines (71 loc) · 2.21 KB
/
importForComparison.py
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
"""
Author: Corneel den Hartogh
Course: Heuristics
Description: Exporting per type of activity on which day it falls for all good rosters
"""
import random
import copy
import json
import time
import glob
from decimal import Decimal
from xlrd import *
from xlwt import *
from xlutils.copy import copy
from csvFilesController import classrooms,subjects,students
from classes import Classroom,Subject,Activity,Student,Roster
import classesImport as ci
from scoreFunction import getScore
from studentOptimization import studentOptimization
from roomOptimization import roomOptimization
excel_file = "activitySpread.xls"
rosters = 0
activityTypes = {}
# select all rosters that score aboven 1400 from 2 different places
for filename in glob.glob('rosters/*.json'):
if float(filename.split("_",2)[1]) >= 1400.00:
rosters += 1
with open(filename) as jsonfile:
data = json.load(jsonfile)
for x in (data["roster"]["activities"]):
activityType = x["activity"]["subject"] + " " + x["activity"]["kind"]
if activityType not in activityTypes.keys():
activityTypes[activityType] = [x["activity"]["slot"][0]]
else:
activityTypes[activityType].append(x["activity"]["slot"][0])
for filename in glob.glob('rosters_server/*.json'):
if float(filename.split("_",3)[2]) >= 1400.00:
rosters += 1
with open(filename) as jsonfile:
data = json.load(jsonfile)
for x in (data["roster"]["activities"]):
activityType = x["activity"]["subject"] + " " + x["activity"]["kind"]
activityTypes[activityType].append(x["activity"]["slot"][0])
# get results in excel
rb = open_workbook(excel_file)
wb = copy(rb)
ws = wb.get_sheet(0)
ws.write(0,7,str(rosters) + " rosters above 1400")
row = 1
for key, values in activityTypes.items():
monday,tuesday,wednesday,thursday,friday = 0,0,0,0,0
for value in values:
if value == 0:
monday += 1
elif value == 1:
tuesday += 1
elif value == 2:
wednesday += 1
elif value == 3:
thursday += 1
elif value == 4:
friday += 1
result = [monday, tuesday, wednesday, thursday, friday]
ws.write(row,7,key)
ws.write(row,8,result[0])
ws.write(row,9,result[1])
ws.write(row,10,result[2])
ws.write(row,11,result[3])
ws.write(row,12,result[4])
row += 1
wb.save(excel_file)