-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
82 lines (63 loc) · 2.45 KB
/
main.py
File metadata and controls
82 lines (63 loc) · 2.45 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
# Importing required functions
import pandas
from poolify import *
from fpdf import FPDF, table
from flask import Flask, flash, render_template, request, abort, send_from_directory, send_file
from fileinput import filename
# Flask constructor
app = Flask(__name__)
# Index page
@app.route('/')
def index():
return render_template('index.html')
# Link to download the template to complete with data
@app.route("/download")
def download():
return send_file("fraction-sheet-template.xlsx")
# Upload function endpoint
@app.post('/upload')
def upload():
# Read the File
file = request.files['file']
# save file in local directory
file.save(file.filename)
# Parse the data as a Pandas DataFrame type (1st row - Sample Info)
sampleInfo = pandas.read_excel(file, sheet_name=0, header=None, nrows=1)
# Select data from DataFrame (1st row - Sample Info)
Br_num = sampleInfo[1][0]
Col_num = int(sampleInfo[4][0])
total_fractions_an = sampleInfo[7][0]
# Pack sample info to be passed later to doit() function
sample = (Br_num, Col_num, total_fractions_an)
# Parse the data as a Pandas DataFrame type (table with fractions information)
tableData = pandas.read_excel(file, sheet_name=0, header=None,
usecols='A:C', skiprows=2,
nrows=total_fractions_an)
fractionData = tableData.transpose()
# Create blank lists that will be populated with experimental data,
# that must be passed to doit()
hu_list = [] # HU: Handling Unit = Fraction no.
aper_list = [] # aper: Area Percent
atot_list = [] # atot: Total Area
input_data = [] # all the data transformed into a list
# Populate the lists with the experimental data from the imported pandas dataframe
i = 0
while i < total_fractions_an:
hu_list.append(int(fractionData[i][0]))
aper_list.append(float(fractionData[i][1]))
atot_list.append(float(fractionData[i][2]))
input_data.append([int(fractionData[i][0]), fractionData[i][1], fractionData[i][2]])
i +=1
# Run the main function doit(), from poolify.py module
try:
doit(sample, hu_list, aper_list, atot_list, input_data)
except:
abort(404)
return send_file("bulletin.pdf")
# Custom 404 Not Found page
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404
# Main Driver Function
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')