This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_io.py
79 lines (58 loc) · 2.19 KB
/
my_io.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
import os
import random as r
import itertools
import matplotlib.pyplot as plt
# set of all co-ordinates involved in the problem, used to prevent overlapping points
reference = set()
colors = itertools.cycle(['orange', 'green', 'purple',
'black', 'blue', 'pink', 'grey', 'yellow', 'cyan'])
markers = itertools.cycle(['s', '.'])
# all functions are crafted for use only in context of this program , not for generic use
def randPOS(): return r.randint(1000, 9999) / 100, r.randint(1000, 9999) / 100
def randVACANCY(): return r.randint(3, 12)
def is_unique(points, reference):
return True if points not in reference else False
def get_unique_pos():
global reference
points = randPOS()
if is_unique(points, reference):
reference.add(points)
return points[0], points[1]
else:
return get_unique_pos()
def plot_points(locatables, title):
m = next(markers)
c = next(colors)
for l in locatables:
plt.scatter(l.x, l.y, marker=m, color=c)
plt.title(title)
plt.savefig(f'{os.getcwd()}/data/{title}.png',
dpi=150, bbox_inches='tight')
plt.show()
# connections is a dictionary where key is exam center and value is list of teachers
def plot_connections(centers):
for center in centers:
color = next(colors)
center.plot_connect_with_teachers(plt, color)
plt.savefig(f'{os.getcwd()}/data/connections.png',
dpi=150, bbox_inches='tight')
plt.show()
def save_to_file(title, locatables, file):
with open(file, 'w+') as f:
f.write(f'{title}\n')
for l in locatables:
if title == 'Teachers':
f.write(f"id={l.id}\t|\tx={l.x}\t|\ty={l.y}\n")
if title == 'ExamCenters':
f.write(
f"id={l.id}\t|\tx={l.x}\t|\ty={l.y}\t|\tvacancy={l.vacancy}\n")
def generateSaveAndPlot(Locatable, count, title):
locatable_objects = []
for i in range(count):
obj = Locatable(i)
locatable_objects.append(obj)
file = f'{os.getcwd()}/data/{title}.txt'
save_to_file(title, locatable_objects, file)
plot_points(locatable_objects, title)
return locatable_objects
# AAHNIK 2020