Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosrun committed May 7, 2023
1 parent fca024a commit 9c5192d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 12 deletions.
2 changes: 2 additions & 0 deletions core/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./simulator /code/simulator
RUN pip install --no-cache-dir -r core/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["uvicorn", "core.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers"]
7 changes: 5 additions & 2 deletions core/functions/project/prescribe.py
Expand Up @@ -26,15 +26,18 @@
logger = logging.getLogger(__name__)


def get_ongoing_dataset_result_key(file: BinaryIO, extension: str, seperator: str,
def get_ongoing_dataset_result_key(file: BinaryIO | bytes, extension: str, seperator: str,
db_project: project_model.Project) -> str:
# Get the result key of the ongoing dataset
result = ""

try:
temp_path = get_new_path(f"{path.TEMP_PATH}/", suffix=f".{extension}")
with open(temp_path, "wb") as f:
f.write(file.read())
if isinstance(file, bytes):
f.write(file)
else:
f.write(file.read())

# Get dataframe from file
try:
Expand Down
3 changes: 2 additions & 1 deletion core/services/event_log.py
Expand Up @@ -48,9 +48,10 @@ def process_uploaded_event_log(file: UploadFile, separator: str, test: UploadFil

# Save test file to memory
if test and test.file:
content = test.file.read()
memory.log_tests[db_event_log.id] = {
"date": datetime.now(),
"file": deepcopy(test.file),
"file": content,
"extension": get_extension(test.filename),
"separator": separator
}
Expand Down
2 changes: 2 additions & 0 deletions core/services/project.py
Expand Up @@ -251,6 +251,8 @@ def process_ongoing_dataset_result(project_id: int, result_key: str, background_
logger.warning("Start to merge the result")
for plugin_result in result["results"].values():
for case_id, case_result in plugin_result.items():
if case_id not in result["cases"]:
continue
result["cases"][case_id]["prescriptions"].append(case_result)
logger.warning("Merge the result successfully")

Expand Down
2 changes: 2 additions & 0 deletions plugins/causallift_resource_allocation/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./plugins /code/plugins
RUN pip install --no-cache-dir -r plugins/causallift_resource_allocation/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["python", "-m", "plugins.causallift_resource_allocation.main"]
2 changes: 2 additions & 0 deletions plugins/causallift_treatment_effect/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./plugins /code/plugins
RUN pip install --no-cache-dir -r plugins/causallift_treatment_effect/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["python", "-m", "plugins.causallift_treatment_effect.main"]
27 changes: 18 additions & 9 deletions plugins/causallift_treatment_effect/algorithm.py
Expand Up @@ -113,15 +113,24 @@ def predict_df(self, df: DataFrame) -> dict:

# Get the result for each length
threads = []
for length, test_df in test_dfs.items():
training_df = self.get_data()["training_dfs"].get(length)
if training_df is None:
continue
t = Thread(target=self.get_result_thread, args=(self, result_dfs, length, training_df, test_df))
t.start()
threads.append(t)
for t in threads:
t.join()
count_of_length = len(test_dfs)
if count_of_length <= 50:
for length, test_df in test_dfs.items():
training_df = self.get_data()["training_dfs"].get(length)
if training_df is None:
continue
t = Thread(target=self.get_result_thread, args=(self, result_dfs, length, training_df, test_df))
t.start()
threads.append(t)
for t in threads:
t.join()
else:
for length, test_df in test_dfs.items():
training_df = self.get_data()["training_dfs"].get(length)
if training_df is None:
continue
result_df = self.get_result(training_df, test_df)
result_dfs[length] = result_df

# Merge the result
if len(result_dfs) <= 0:
Expand Down
2 changes: 2 additions & 0 deletions plugins/knn_next_activity/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./plugins /code/plugins
RUN pip install --no-cache-dir -r plugins/knn_next_activity/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["python", "-m", "plugins.knn_next_activity.main"]
2 changes: 2 additions & 0 deletions plugins/random_forest_alarm/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./plugins /code/plugins
RUN pip install --no-cache-dir -r plugins/random_forest_alarm/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["python", "-m", "plugins.random_forest_alarm.main"]
2 changes: 2 additions & 0 deletions processor/Dockerfile
Expand Up @@ -3,4 +3,6 @@ WORKDIR /code
COPY ./core /code/core
COPY ./processor /code/processor
RUN pip install --no-cache-dir -r processor/requirements.txt
ENV PYTHONUNBUFFERED=1
ENV PYTHONIOENCODING=UTF-8
CMD ["python", "-m", "processor.main"]

0 comments on commit 9c5192d

Please sign in to comment.