-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b2b329d
Showing
14 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## Note | ||
In order to run the bash file: inside the target dir and run `chmod +x file_name.sh` for example: `chmod +x delete.sh` |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rm output/* |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
|
||
# from collections import defaultdict | ||
from datetime import datetime | ||
import pandas as pd | ||
|
||
|
||
|
||
def process_excel(): | ||
files = os.listdir('./input') | ||
# files = os.listdir(filename) | ||
path = os.getcwd() + '/input' | ||
temp = [] | ||
# path = os.getcwd() + filename | ||
for filename in files: | ||
# if filename.endswith('.xlsx') and len(files) != 1: | ||
# file = pd.read_excel(os.path.join(path, 'test.xlsx')) | ||
# file1 = pd.read_excel(os.path.join(path, 'test1.xlsx')) | ||
if filename.endswith('.xlsx'): | ||
temp.append(filename) | ||
if len(temp) == 2: | ||
file = pd.read_excel(os.path.join(path, 'Table_B.xlsx')) | ||
file1 = pd.read_excel(os.path.join(path, 'Table_A.xlsx')) | ||
|
||
df = file[['控制点编号','TSP mapping','控制点描述(2023)']] | ||
df1 = df['TSP mapping'].str.split('\n').tolist() | ||
df_control = file[['控制点编号','控制点描述(2023)']] | ||
df_control_map = {} | ||
for i in range(len(df_control)): | ||
df_control_map[df_control.iloc[i, 0]] = df_control.iloc[i, 1] | ||
file1 = file1[['标准编号','标准描述']].dropna() | ||
df_discrip = file['控制点描述(2023)'] | ||
dic = {} | ||
dic_control = {} | ||
standard_disc = {} | ||
for i in range(len(file1)): | ||
standard_disc[file1.iloc[i, 0]] = file1.iloc[i, 1] | ||
for i in range(len(df1)): | ||
for key in df1[i]: | ||
if key not in dic: | ||
dic[key] = [df_control.iloc[i, 0]] | ||
else: | ||
dic[key].append(df_control.iloc[i, 0]) | ||
res_dic = {'标准编号':[], '标准描述':[], '控制编号':[], '控制点描述(2023)':[]} | ||
for key in dic: | ||
for i in range(len(dic[key])): | ||
res_dic['标准编号'].append(key) | ||
res_dic['标准描述'].append(standard_disc[key]) | ||
res_dic['控制编号'].append(dic[key][i]) | ||
res_dic['控制点描述(2023)'].append(df_control_map[dic[key][i]]) | ||
|
||
res = pd.DataFrame(res_dic) | ||
res = res.set_index(['标准编号','标准描述','控制编号']) | ||
# res.to_excel('./output/result.xlsx') | ||
filename = f'result_{str(datetime.now())}.xlsx' | ||
res.to_excel(f'./output/{filename}') | ||
# return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
|
||
# from collections import defaultdict | ||
from datetime import datetime | ||
import pandas as pd | ||
|
||
|
||
|
||
def process_excel_sorted(): | ||
files = os.listdir('./input') | ||
# files = os.listdir(filename) | ||
path = os.getcwd() + '/input' | ||
temp = [] | ||
# path = os.getcwd() + filename | ||
for filename in files: | ||
# if filename.endswith('.xlsx') and len(files) != 1: | ||
# file = pd.read_excel(os.path.join(path, 'test.xlsx')) | ||
# file1 = pd.read_excel(os.path.join(path, 'test1.xlsx')) | ||
if filename.endswith('.xlsx'): | ||
temp.append(filename) | ||
if len(temp) == 2: | ||
file = pd.read_excel(os.path.join(path, 'Table_B.xlsx')) | ||
file1 = pd.read_excel(os.path.join(path, 'Table_A.xlsx')) | ||
|
||
df = file[['控制点编号','TSP mapping','控制点描述(2023)']] | ||
df1 = df['TSP mapping'].str.split('\n').tolist() | ||
df_control = file[['控制点编号','控制点描述(2023)']] | ||
df_control_map = {} | ||
for i in range(len(df_control)): | ||
df_control_map[df_control.iloc[i, 0]] = df_control.iloc[i, 1] | ||
file1 = file1[['标准编号','标准描述']].dropna() | ||
df_discrip = file['控制点描述(2023)'] | ||
dic = {} | ||
dic_control = {} | ||
standard_disc = {} | ||
for i in range(len(file1)): | ||
standard_disc[file1.iloc[i, 0]] = file1.iloc[i, 1] | ||
for i in range(len(df1)): | ||
for key in df1[i]: | ||
if key not in dic: | ||
dic[key] = [df_control.iloc[i, 0]] | ||
else: | ||
dic[key].append(df_control.iloc[i, 0]) | ||
res_dic = {'标准编号':[], '标准描述':[], '控制编号':[], '控制点描述(2023)':[]} | ||
for key in dic: | ||
for i in range(len(dic[key])): | ||
res_dic['标准编号'].append(key) | ||
res_dic['标准描述'].append(standard_disc[key]) | ||
res_dic['控制编号'].append(dic[key][i]) | ||
res_dic['控制点描述(2023)'].append(df_control_map[dic[key][i]]) | ||
|
||
res = pd.DataFrame(res_dic) | ||
res = res.set_index(['标准编号','标准描述','控制编号']) | ||
# res.to_excel('./output/result.xlsx') | ||
res1 = res.sort_values(by=['标准编号'], ascending=[True]) | ||
filename = f'result_sorted_{str(datetime.now())}.xlsx' | ||
res1.to_excel(f'./output/{filename}') | ||
# return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
flask | ||
pandas | ||
pywebview | ||
werkzeug==2.2.2 | ||
Flask==2.0.3 | ||
openpyxl | ||
Pyarrow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rm input/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from flask import Flask, render_template, request, redirect, url_for | ||
import pandas as pd | ||
# Import the Maths package here | ||
# import webview | ||
import os | ||
import subprocess | ||
from subprocess import Popen, PIPE | ||
|
||
from flask import Flask, request, render_template, redirect, url_for, send_from_directory | ||
from werkzeug.utils import secure_filename | ||
from mapping import process_excel | ||
from mapping_sort import process_excel_sorted | ||
|
||
ALLOWED_EXTENSIONS = set(['xlsx']) | ||
|
||
def allowed_file(filename): | ||
return '.' in filename and \ | ||
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS | ||
|
||
app = Flask("Mapping") | ||
# window = webview.create_window('Mapping', app) | ||
|
||
@app.route("/", methods = ['GET', 'POST']) | ||
def render_index_page(): | ||
# Write your code here | ||
# os.system('mkdir input') | ||
if os.listdir(os.getcwd() + '/input'): | ||
subprocess.Popen('./script.sh', shell=True) | ||
return render_template('index.html', files = os.listdir(os.getcwd() + '/example'), download=sorted(os.listdir('output'))) | ||
|
||
@app.route('/<name>') | ||
def default_file(name): | ||
# return redirect(url_for('download_file', name=name)) | ||
return send_from_directory('example', name) | ||
# return send_file(os.getcwd() + '/example' + name, as_attachment=True) | ||
|
||
# @app.route("/data", methods = ['GET', 'POST']) | ||
# def data(): | ||
# if request.method == 'POST': | ||
# file = request.form['upload-file'] | ||
# data = pd.read_excel(file) | ||
# return render_template('data.html', data=data.to_excel) | ||
|
||
@app.route('/upload', methods=['GET', 'POST']) | ||
def upload(): | ||
# subprocess.call('script.sh') | ||
if request.method == 'POST': | ||
file = request.files['file'] | ||
if file and allowed_file(file.filename): | ||
filename = secure_filename(file.filename) | ||
# new_filename = f'{filename.split(".")[0]}_{str(datetime.now())}.xlsx' | ||
save_location = os.path.join('input', filename) | ||
file.save(save_location) | ||
files = os.listdir('./input') | ||
# print("Uploaded successfully") | ||
|
||
temp = [] | ||
for subfile in files: | ||
if subfile.endswith('.xlsx'): | ||
temp.append(subfile) | ||
if len(temp) == 2: | ||
output_file = process_excel() | ||
#return send_from_directory('output', output_file) | ||
return redirect(url_for('download')) | ||
# return redirect(url_for('index.html')) | ||
# render_template('index.html') | ||
# else: | ||
# return redirect(url_for('index')) | ||
|
||
# files1 = os.listdir('example') | ||
return render_template('index.html', uploaded=os.listdir('input'), files = os.listdir(os.getcwd() + '/example'), download=os.listdir('output')) | ||
|
||
@app.route('/upload/<upload_name>') | ||
def upload_files(upload_name): | ||
return send_from_directory('input', upload_name) | ||
|
||
@app.route('/upload/<name>') | ||
def upload_default_files(name): | ||
return send_from_directory('example', name) | ||
|
||
@app.route('/download') | ||
def download(): | ||
subprocess.Popen('./script.sh', shell=True) | ||
return render_template('index.html', download=sorted(os.listdir('output')), files = os.listdir(os.getcwd() + '/example')) | ||
|
||
@app.route('/download/<filename>') | ||
def download_file(filename): | ||
return send_from_directory('output', filename) | ||
|
||
@app.route('/delete') | ||
def delete_result(): | ||
subprocess.Popen('./delete.sh', shell=True) | ||
return render_template('index.html', files = os.listdir(os.getcwd() + '/example')) | ||
|
||
@app.route('/sort', methods=['GET', 'POST']) | ||
def sort(): | ||
if request.method == 'POST': | ||
file = request.files['file'] | ||
if file and allowed_file(file.filename): | ||
filename = secure_filename(file.filename) | ||
save_location = os.path.join('input', filename) | ||
file.save(save_location) | ||
files = os.listdir('./input') | ||
|
||
temp = [] | ||
for subfile in files: | ||
if subfile.endswith('.xlsx'): | ||
temp.append(subfile) | ||
if len(temp) == 2: | ||
output_file = process_excel_sorted() | ||
return redirect(url_for('download')) | ||
return render_template('index.html', uploaded=os.listdir('input'), files = os.listdir(os.getcwd() + '/example'), download=os.listdir('output')) | ||
|
||
if __name__ == "__main__": | ||
app.run(host="0.0.0.0", port=8080) | ||
# webview.start() |
Binary file not shown.
Oops, something went wrong.