diff --git a/scipaperloader/__init__.py b/scipaperloader/__init__.py index 9cdaa9d..6d48825 100644 --- a/scipaperloader/__init__.py +++ b/scipaperloader/__init__.py @@ -1,6 +1,7 @@ from flask import Flask from .config import Config from .db import db +from .models import init_schedule_config def create_app(test_config=None): app = Flask(__name__) @@ -13,6 +14,7 @@ def create_app(test_config=None): with app.app_context(): db.create_all() + init_schedule_config() @app.context_processor def inject_app_title(): diff --git a/scipaperloader/db.py b/scipaperloader/db.py index 4b9ac56..2e1eeb6 100644 --- a/scipaperloader/db.py +++ b/scipaperloader/db.py @@ -1,6 +1,3 @@ -from flask_sqlalchemy import SQLAlchemy, current_app, g - -db = SQLAlchemy() - -db_name = 'scipaperloader.db' +from flask_sqlalchemy import SQLAlchemy +db = SQLAlchemy() \ No newline at end of file diff --git a/scipaperloader/models.py b/scipaperloader/models.py index f7d7b0e..f373845 100644 --- a/scipaperloader/models.py +++ b/scipaperloader/models.py @@ -16,4 +16,38 @@ class Paper(db.Model): class ScheduleConfig(db.Model): hour = db.Column(db.Integer, primary_key=True) # 0-23 - volume = db.Column(db.Float) # weight or count \ No newline at end of file + weight = db.Column(db.Float) # weight + +class VolumeConfig(db.Model): + id = db.Column(db.Integer, primary_key=True) + volume = db.Column(db.Float) # volume of papers to scrape per day + +def init_schedule_config(): + """Initialize ScheduleConfig with default values if empty""" + if ScheduleConfig.query.count() == 0: + # Default schedule: Lower volume during business hours, + # higher volume at night + default_schedule = [ + # Night hours (higher volume) + *[(hour, 1.0) for hour in range(0, 6)], + # Morning hours (low volume) + *[(hour, 0.3) for hour in range(6, 9)], + # Business hours (very low volume) + *[(hour, 0.2) for hour in range(9, 17)], + # Evening hours (medium volume) + *[(hour, 0.5) for hour in range(17, 21)], + # Late evening (high volume) + *[(hour, 0.8) for hour in range(21, 24)] + ] + + for hour, weight in default_schedule: + config = ScheduleConfig(hour=hour, weight=weight) + db.session.add(config) + + db.session.commit() + + if VolumeConfig.query.count() == 0: + # Default volume configuration + default_volume = VolumeConfig(volume=100) + db.session.add(default_volume) + db.session.commit() \ No newline at end of file diff --git a/scipaperloader/templates/schedule.html b/scipaperloader/templates/schedule.html new file mode 100644 index 0000000..d3101c7 --- /dev/null +++ b/scipaperloader/templates/schedule.html @@ -0,0 +1,222 @@ +{% extends 'base.html' %} +{% block content %} + + + + + +
+ Click to select one or more hours below. Then assign a weight to them using the input and apply it. Color indicates relative intensity. The total daily volume will be split proportionally across these weights. +
+ +The total volume of data to be downloaded each day is papers.
+ ++ Click to select one or more hours below. Then assign a weight to them using the input and apply it. Color indicates relative intensity. The total daily volume will be split proportionally across these weights. +
+ +