DavidD003 commited on
Commit
d962c11
·
1 Parent(s): 3236e99

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +112 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datetime import datetime
3
+ #Just in case:
4
+ import openpyxl as pyxl
5
+ import pandas as pd
6
+ import numpy as np
7
+ from copy import deepcopy
8
+ #######################
9
+ #First define the functions
10
+ def PrimeVisualTemplate(inp,dummyInp1,dummyInp2):
11
+ #In real program, all inp files are used in transforming the 'main' input sheet.
12
+ #After transformation ('priming'), the primed sheet is sent to the 'primed file' container on both tab A and B. And the other sheets that are required for the transformation are also passed along to sheet B
13
+ #In this dummy program, the main sheet simply has a new sheet added to the workbook
14
+ #and then the same files are transferred to the same destinations
15
+ wb = pyxl.load_workbook(filename = 'init.xlsx')
16
+ ws2 = wb.create_sheet(title="PrimeSheet")
17
+ PrimedFlNm='primed.xlsx'
18
+ wb.save(filename = PrimedFlNm)
19
+ return PrimedFlNm,PrimedFlNm,datetime.now(),datetime.now(),dummyInp1.name,dummyInp2.name
20
+
21
+ def GenerateSchedule(schedWWF,xtraDays,wkHrs,DaysCrew,AssnFl,FTrefFl,TempRefFl,PollFl,stop1=0,stop2=0,template=False):
22
+ #In the real program, this function is called on tab B and C. Tab B is the main call wherein the schedule is being built
23
+ #The Tab C call allows for forcing stop mid-schedule build to observe the process in progress
24
+ #In this dummy program, the function simply generates an array of numbers in the 'PrimeSheet' previously generated
25
+ #When called from tab C, can stop this enumeration of values by specifying the two indices at which to cancel
26
+ #The only input used is the 'Primed Template' from previously and the stop condition.
27
+ stop=(stop1,stop2)
28
+ wb = pyxl.load_workbook(filename = AssnFl)
29
+ ws=wb['PrimeSheet']
30
+ for r in range(1,11):
31
+ for c in range(1,11):
32
+ if c==stop1 and r==stop2:
33
+ flNm='Generated,'+str(c)+','+str(r)+'.xlsx'
34
+ wb.save(filename = flNm)
35
+ return flNm, datetime.now()
36
+ ws.cell(row=r,column=c).value=c*r
37
+ flNm='Generated.xlsx'
38
+ wb.save(filename = flNm)
39
+ return flNm,datetime.now()
40
+
41
+ def GenerateSchedule1(schedWWF,xtraDays,wkHrs,DaysCrew,AssnFl,FTrefFl,TempRefFl,PollFl,stop=None,template=True):
42
+ #In the real program, this function is used to perform a slightly different function, taking all the inputs from tab B
43
+ #In the dummy program, this simply generates a new sheet indicating it was run
44
+ wb = pyxl.load_workbook(filename = AssnFl)
45
+ ws2 = wb.create_sheet(title="Option-C")
46
+ PrimedFlNm='opt-C.xlsx'
47
+ wb.save(filename = PrimedFlNm)
48
+ return PrimedFlNm,datetime.now()
49
+
50
+
51
+ #######################
52
+ #Second Defining the Interface
53
+ with gr.Blocks() as demo:
54
+ with gr.Tab("A - Visual Template Builder"):
55
+ gr.Markdown("On this tab you can input a purely visual template (assignment tables empty) and have it primed for use in the scheduling algorithm. The info generated here will also be sent as inputs to tab B. See the documentation for more details on required formatting")
56
+ with gr.Row():
57
+ A_fl_FTref=gr.File(label="Full Time Refusals Sheet")
58
+ A_fl_Tref=gr.File(label="Temp Refusal Sheet")
59
+ with gr.Row():
60
+ A_fl_VT=gr.File(label="Visual Template File")
61
+ with gr.Column():
62
+ A_fl_PT=gr.File(label="Primed Template File")
63
+ A_tx_PTtimestamp=gr.Textbox(label="File Change Timestamp - Primed Template",placeholder="Waiting for file")
64
+ A_bt_PT = gr.Button("Prime Visual Template")
65
+ with gr.Tab("B - Scheduler"):
66
+ gr.Markdown("On this tab the inputs are used to generate a weekend schedule. The Template and refusal sheet files are carried over (with slightly garbled names) when generated using tab A. The schedule is considered 'primed' when the tables on the secondary sheets match what is indicated on the visual template. The other inputs on this sheet should be selected per the circumstances. For example. If Friday is part of the weekend to be scheduled, Select '32 hrs', 'Friday', and 'yes to WWF scheduling'. Normal non-long weekend will not assign OT to WWF, and be 40 hour weeks without Friday or Monday to be scheduled.")
67
+ with gr.Row():
68
+ B_fl_FTref=gr.File(label="Full Time Refusals Sheet")
69
+
70
+ B_fl_Tref=gr.File(label="Temp Refusal Sheet")
71
+ with gr.Row():
72
+ with gr.Column():
73
+ B_fl_PT=gr.File(label="Primed Template File")
74
+ B_tx_PTtimestamp=gr.Textbox(label="File Change Timestamp - Primed Template",placeholder="Waiting for file")
75
+ with gr.Column():
76
+ with gr.Row():
77
+ B_fl_Pl=gr.File(label="Polling File")
78
+ with gr.Tab("Non-File Inputs"):
79
+ with gr.Row():
80
+ B_wwfOT=gr.Radio(["Yes", "No"],label="Assign OT to WWF? (If 'yes', WWF will be considered for filling in slots beyond their prescribed shifts in the Assignment List)")
81
+ B_dayCrew=gr.Radio(["Bud","Blue"],label="Which crew is on A shift this week?")
82
+ with gr.Row():
83
+ B_wkHrs=gr.Radio([32, 40],label="Regular Work Hours This Week?")
84
+ B_xtraDay=gr.CheckboxGroup(["Friday", "Monday"], label="Check the boxes as appropriate if scheduling long weekend")
85
+ B_bt_MS = gr.Button("Generate Schedule")
86
+ B_fl_FS=gr.File(label="Generated Schedule")
87
+ B_tx_FTtimestamp=gr.Textbox(label="File Change Timestamp - Completed Schedule",placeholder="Waiting for first run")
88
+ with gr.Tab("C - Review"):
89
+ with gr.Tab("Inspect Template"):
90
+ gr.Markdown("On this tab you can have the program generate a schedule using only the template file so as to confirm the template was entered correctly for program interpretation. This process builds the template using all inputs present in tab B. Inputs are required for building the template.")
91
+ C_bt_MT = gr.Button("Generate Template")
92
+ C_fl_T=gr.File(label="Generated Template")
93
+ C_tx_Ttimestamp=gr.Textbox(label="File Change Timestamp - Generated Template",placeholder="Waiting for first run.")
94
+ with gr.Tab("Force Stop Mid-Scheduling"):
95
+ gr.Markdown("On this tab you can observe what a schedule looked like after making a specific number of assignments. Iteration number can be retrieved from the bottom of the verbose assignment list tab of a generated schedule. If the specified iteration and assignment number combination are not encountered, this function will simply re generate the entire schedule. This function only quits schedule building after the template. An assignment number within the template building portion will not be quit on, and it will proceed to build full schedule.")
96
+ with gr.Row():
97
+ with gr.Column():
98
+ with gr.Row():
99
+ C_nm_PS = gr.Number(label="Limit Number for Total Assignments")
100
+ C_nm_IN = gr.Number(label="Iteration Number To Stop On")
101
+ with gr.Column():
102
+ C_fl_PS=gr.File(label="Partially Complete Schedule")
103
+ C_tx_ts2 = gr.Textbox(label="Time Of Partial Schedule Generation",placeholder="N/A")
104
+ C_bt_PS = gr.Button("Partially Generate Schedule")
105
+
106
+ #######################
107
+ #Third Define the Interactions
108
+ A_bt_PT.click(PrimeVisualTemplate,[A_fl_VT,A_fl_FTref,A_fl_Tref],[A_fl_PT,B_fl_PT,A_tx_PTtimestamp,B_tx_PTtimestamp,B_fl_FTref,B_fl_Tref])
109
+ B_bt_MS.click(GenerateSchedule,[B_wwfOT,B_xtraDay,B_wkHrs,B_dayCrew,B_fl_PT,B_fl_FTref,B_fl_Tref,B_fl_Pl],[B_fl_FS,B_tx_FTtimestamp])
110
+ C_bt_MT.click(GenerateSchedule1,[B_wwfOT,B_xtraDay,B_wkHrs,B_dayCrew,B_fl_PT,B_fl_FTref,B_fl_Tref,B_fl_Pl],[C_fl_T,C_tx_Ttimestamp])
111
+ C_bt_PS.click(GenerateSchedule,[B_wwfOT,B_xtraDay,B_wkHrs,B_dayCrew,B_fl_PT,B_fl_FTref,B_fl_Tref,B_fl_Pl,C_nm_IN,C_nm_PS],[C_fl_PS,C_tx_ts2])
112
+ demo.launch()