Compare commits
4 Commits
3772f83d11
...
f93e45b827
| Author | SHA1 | Date | |
|---|---|---|---|
| f93e45b827 | |||
| 075e1fba85 | |||
| a4c527ce5b | |||
| 6d60820800 |
@@ -23,6 +23,7 @@ services:
|
||||
container_name: crosspost_flask
|
||||
volumes:
|
||||
- .:/app
|
||||
- model_cache:/models
|
||||
env_file:
|
||||
- .env
|
||||
ports:
|
||||
@@ -36,6 +37,7 @@ services:
|
||||
build: .
|
||||
volumes:
|
||||
- .:/app
|
||||
- model_cache:/models
|
||||
container_name: crosspost_worker
|
||||
env_file:
|
||||
- .env
|
||||
@@ -46,3 +48,6 @@ services:
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
|
||||
volumes:
|
||||
model_cache:
|
||||
@@ -3,7 +3,7 @@ import pandas as pd
|
||||
from server.analysis.nlp import NLP
|
||||
|
||||
class DatasetEnrichment:
|
||||
def __init__(self, df, topics):
|
||||
def __init__(self, df: pd.DataFrame, topics: dict):
|
||||
self.df = self._explode_comments(df)
|
||||
self.topics = topics
|
||||
self.nlp = NLP(self.df, "title", "content", self.topics)
|
||||
|
||||
@@ -16,7 +16,7 @@ from flask_jwt_extended import (
|
||||
|
||||
from server.analysis.stat_gen import StatGen
|
||||
from server.analysis.enrichment import DatasetEnrichment
|
||||
from server.exceptions import NotAuthorisedException, NotExistentDatasetException
|
||||
from server.exceptions import NotAuthorisedException, NonExistentDatasetException
|
||||
from server.db.database import PostgresConnector
|
||||
from server.core.auth import AuthManager
|
||||
from server.core.datasets import DatasetManager
|
||||
@@ -162,7 +162,7 @@ def get_dataset(dataset_id):
|
||||
return jsonify(filtered_dataset), 200
|
||||
except NotAuthorisedException:
|
||||
return jsonify({"error": "User is not authorised to access this content"}), 403
|
||||
except NotExistentDatasetException:
|
||||
except NonExistentDatasetException:
|
||||
return jsonify({"error": "Dataset does not exist"}), 404
|
||||
except Exception:
|
||||
print(traceback.format_exc())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pandas as pd
|
||||
from server.db.database import PostgresConnector
|
||||
from psycopg2.extras import Json
|
||||
from server.exceptions import NotAuthorisedException
|
||||
from server.exceptions import NotAuthorisedException, NonExistentDatasetException
|
||||
|
||||
class DatasetManager:
|
||||
def __init__(self, db: PostgresConnector):
|
||||
@@ -23,7 +23,11 @@ class DatasetManager:
|
||||
def get_dataset_info(self, dataset_id: int) -> dict:
|
||||
query = "SELECT * FROM datasets WHERE id = %s"
|
||||
result = self.db.execute(query, (dataset_id,), fetch=True)
|
||||
return result[0] if result else None
|
||||
|
||||
if not result:
|
||||
raise NonExistentDatasetException(f"Dataset {dataset_id} does not exist")
|
||||
|
||||
return result[0]
|
||||
|
||||
def save_dataset_info(self, user_id: int, dataset_name: str, topics: dict) -> int:
|
||||
query = """
|
||||
@@ -34,11 +38,6 @@ class DatasetManager:
|
||||
result = self.db.execute(query, (user_id, dataset_name, Json(topics)), fetch=True)
|
||||
return result[0]["id"] if result else None
|
||||
|
||||
def get_dataset_content(self, dataset_id: int) -> pd.DataFrame:
|
||||
query = "SELECT * FROM events WHERE dataset_id = %s"
|
||||
result = self.db.execute(query, (dataset_id,), fetch=True)
|
||||
return pd.DataFrame(result)
|
||||
|
||||
def save_dataset_content(self, dataset_id: int, event_data: pd.DataFrame):
|
||||
if event_data.empty:
|
||||
return
|
||||
|
||||
@@ -27,19 +27,21 @@ class PostgresConnector:
|
||||
self.connection.autocommit = False
|
||||
|
||||
def execute(self, query, params=None, fetch=False) -> list:
|
||||
try:
|
||||
with self.connection.cursor(cursor_factory=RealDictCursor) as cursor:
|
||||
cursor.execute(query, params)
|
||||
if fetch:
|
||||
return cursor.fetchall()
|
||||
result = cursor.fetchall() if fetch else None
|
||||
self.connection.commit()
|
||||
return result
|
||||
except Exception:
|
||||
self.connection.rollback()
|
||||
raise
|
||||
|
||||
def execute_batch(self, query, values):
|
||||
with self.connection.cursor(cursor_factory=RealDictCursor) as cursor:
|
||||
execute_batch(cursor, query, values)
|
||||
self.connection.commit()
|
||||
|
||||
|
||||
## User Management Methods
|
||||
def close(self):
|
||||
if self.connection:
|
||||
self.connection.close()
|
||||
@@ -1,7 +1,7 @@
|
||||
class NotAuthorisedException(Exception):
|
||||
pass
|
||||
|
||||
class NotExistentDatasetException(Exception):
|
||||
class NonExistentDatasetException(Exception):
|
||||
pass
|
||||
|
||||
class DatabaseNotConfiguredException(Exception):
|
||||
|
||||
Reference in New Issue
Block a user