This repository was archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaAssign.py
More file actions
43 lines (32 loc) · 1.36 KB
/
Copy pathAreaAssign.py
File metadata and controls
43 lines (32 loc) · 1.36 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
import openpyxl
import random
# loads the already existing DSASurvey.xlsx
# read the xl file and create the list of areas present with repitation
# repitation is kept to retain the probability of an area being randomly assigned for the sake of beta project
def readArea():
Area = openpyxl.load_workbook(filename='DSASurvey.xlsx')
AreaSheet = Area.active
AreaList = []
for i in range(2, AreaSheet.max_row+1):
temp = 'B' + str(i)
AreaList.append(AreaSheet[temp].value)
return AreaList
# Passed as the parameter is the area list we get from readArea() function
# uses this list to randomly return an element from the list
def getRandomArea(AL):
Upperbound = len(AL)-1
Lowerbound = 0
RandomIndex = random.randint(Lowerbound, Upperbound)
return AL[RandomIndex]
# Opens the pre-existing Data.xlsx file
# creates an additional column named Area
# randomly assign area to every student and save the file as Database.xlsx
def main():
Database = openpyxl.load_workbook(filename='Data.xlsx')
MainSheet = Database.active
MainSheet['E1'] = 'Area'
for i in range(2, MainSheet.max_row+1):
Col = 'E' + str(i)
MainSheet[Col] = getRandomArea(readArea())
Database.save(filename='Database.xlsx')
# main() #Un-comment to run it again and re-create Database.xlsx file