Skip to content

Commit 039a731

Browse files
authored
Merge pull request #9 from hippolyteblot/fixe-lcmodeldata
using env var for the cache folder
2 parents 56e9092 + 1aa0534 commit 039a731

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

src/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# local imports
1919
from utils.settings import (APP_HOST, APP_PORT, APP_DEBUG, DEV_TOOLS_PROPS_CHECK, SSL_CERT_CHAIN, SSL_SERVER_KEY,
20-
get_DB, PRODUCTION)
20+
get_DB, PRODUCTION, CACHE_FOLDER)
2121

2222
from components import navbar, footer
2323
from components.login import User, login_location
@@ -64,8 +64,8 @@ def serve_layout():
6464
local_app.layout = serve_layout # set the layout to the serve_layout function
6565

6666
# create a tmp folder if it does not exist
67-
if not os.path.exists('src/tmp'):
68-
os.makedirs('src/tmp')
67+
if not os.path.exists(CACHE_FOLDER):
68+
os.makedirs(CACHE_FOLDER)
6969

7070
login_manager = LoginManager()
7171
login_manager.init_app(server)

src/models/home.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@
1616
from utils.settings import get_DB, CACHE_FOLDER
1717

1818

19-
def load_exec_from_local() -> list:
20-
"""Load the executions from the local folder"""
21-
folder = "src/data/spectro/"
22-
exec_list = []
23-
for group in ["A", "B"]:
24-
for subfolder in os.listdir(folder + group):
25-
voxel = subfolder.split("_Vox")[1]
26-
exec_number = int(subfolder.split("_")[0].split("Rec")[1])
27-
28-
execution = {
29-
"path": group + "/" + subfolder + "/",
30-
"name": "parameters " + group + ", voxel " + voxel + ", execution " + str(exec_number)
31-
}
32-
exec_list.append(execution)
33-
return exec_list
34-
35-
3619
def load_exp_from_db():
3720
"""Load the experiments from the local folder"""
3821
# query = 'SELECT * FROM EXPERIMENTS INNER JOIN USERS U ON EXPERIMENTS.user_id = U.id WHERE EXPERIMENTS.single = 0'

src/models/spectro_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from dash import html
1212
from pandas import DataFrame
1313

14-
from utils.settings import get_GVC
14+
from utils.settings import get_GVC, CACHE_FOLDER
1515
from utils.spectro_reader import get_quest2, get_lcmodel, parse_lcmodel
1616
from utils.settings import get_DB
1717

@@ -39,14 +39,14 @@ def get_cquest_experiment_data(experiment_id: int) -> pd.DataFrame:
3939

4040
def read_cquest_file(file_uuid: str) -> DataFrame:
4141
"""Read the file uploaded by the user using the uuid and return a dataframe"""
42-
path = os.path.join("src", "tmp", "user_compare", str(file_uuid) + ".txt")
42+
path = os.path.join(CACHE_FOLDER, "user_compare", str(file_uuid) + ".txt")
4343
data = get_quest2(path)
4444
return data
4545

4646

4747
def read_lcmodel_file(file_uuid: str) -> DataFrame:
4848
"""Read the file uploaded by the user using the uuid and return a dataframe"""
49-
path = os.path.join("src", "tmp", "user_compare", str(file_uuid) + ".table")
49+
path = os.path.join(CACHE_FOLDER, "user_compare", str(file_uuid) + ".table")
5050
data, diag = get_lcmodel(path)
5151
data = parse_lcmodel(data, diag)
5252
return data
@@ -78,30 +78,30 @@ def get_metadata_cquest(exp_id: int) -> list:
7878

7979
def get_files_in_folder(folder_id, extension='txt'):
8080
"""Get the files in a folder from user's folder in local"""
81-
path = os.path.join("src", "tmp", "user_compare", str(folder_id))
81+
path = os.path.join(CACHE_FOLDER, "user_compare", str(folder_id))
8282
files = os.listdir(path)
8383
files = [file for file in files if file.endswith(f".{extension}")]
8484
return files
8585

8686

8787
def read_file_in_folder_cquest(folder, file):
8888
"""Read the file uploaded by the user using the uuid and return a dataframe"""
89-
path = os.path.join("src", "tmp", "user_compare", str(folder), str(file))
89+
path = os.path.join(CACHE_FOLDER, "user_compare", str(folder), str(file))
9090
data = get_quest2(path)
9191
return data
9292

9393

9494
def read_file_in_folder_lcmodel(folder, file):
9595
"""Read the file uploaded by the user using the uuid and return a dataframe"""
96-
path = os.path.join("src", "tmp", "user_compare", str(folder), str(file))
96+
path = os.path.join(CACHE_FOLDER, "user_compare", str(folder), str(file))
9797
data, diag = get_lcmodel(path)
9898
data = parse_lcmodel(data, diag)
9999
return data
100100

101101

102102
def read_folder_cquest(folder):
103103
"""Read all the files in a folder and return a dataframe containing all the data"""
104-
path = os.path.join("src", "tmp", "user_compare", str(folder))
104+
path = os.path.join(CACHE_FOLDER, "user_compare", str(folder))
105105
files = os.listdir(path)
106106
files = [file for file in files if file.endswith(".txt")]
107107
data = pd.DataFrame()
@@ -114,7 +114,7 @@ def read_folder_cquest(folder):
114114

115115
def read_folder_lcmodel(folder):
116116
"""Read all the files in a folder and return a dataframe containing all the data"""
117-
path = os.path.join("src", "tmp", "user_compare", str(folder))
117+
path = os.path.join(CACHE_FOLDER, "user_compare", str(folder))
118118
files = os.listdir(path)
119119
files = [file for file in files if file.endswith(".table")]
120120
data = pd.DataFrame()

src/models/visualize_experiment_template.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
import pandas as pd
66

7+
from settings import CACHE_FOLDER
8+
79

810
def read_file(filename):
911
"""Read a file from the tmp folder. The file can be a csv, xlsx or feather file."""
1012
ext = filename.split('.')[-1]
1113

1214
if ext == 'feather':
13-
data = pd.read_feather('src/tmp/' + filename)
15+
data = pd.read_feather(CACHE_FOLDER + filename)
1416
elif ext == 'xlsx':
15-
data = pd.read_excel('src/tmp/' + filename)
17+
data = pd.read_excel(CACHE_FOLDER + filename)
1618
else:
17-
data = pd.read_csv('src/tmp/' + filename)
19+
data = pd.read_csv(CACHE_FOLDER + filename)
1820
return data

src/views/visualize_experiment_template.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import plotly.express as px
1212

1313
from models.visualize_experiment_template import read_file
14+
from settings import CACHE_FOLDER
1415

1516

1617
def layout():
@@ -542,7 +543,7 @@ def update_dropdowns(contents, filename):
542543
md5 = hashlib.md5(b64).hexdigest()
543544
ext = filename[0].split('.')[-1]
544545
new_filename = md5 + '.' + ext
545-
with open('src/tmp/' + new_filename, 'wb') as f:
546+
with open(CACHE_FOLDER + new_filename, 'wb') as f:
546547
f.write(base64.b64decode(content_string))
547548
try:
548549
data = read_file(new_filename)

0 commit comments

Comments
 (0)