Skip to content

Commit

Permalink
Refactor RCDB web site code
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jan 15, 2025
1 parent cca08b3 commit cf274da
Show file tree
Hide file tree
Showing 180 changed files with 192 additions and 234 deletions.
1 change: 0 additions & 1 deletion python/rcdb/rcdb_cli/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
def ls(context, search, is_long):
"""Lists conditions"""


db = context.db
assert isinstance(db, RCDBProvider)
cnd_types = db.get_condition_types_by_name()
Expand Down
76 changes: 76 additions & 0 deletions python/rcdb/rcdb_cli/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import click

from rcdb.provider import RCDBProvider
from .context import pass_rcdb_context


@click.command()
@click.argument('run_index', required=False)
@click.argument('condition', required=False)
@pass_rcdb_context
def ls(context, run_index, condition):
"""Lists conditions"""

db = context.db
assert isinstance(db, RCDBProvider)



def show_value(db, run_number, name):
"""
Shows condition value for run
:param db: RCDBProvider to database
:type db: RCDBProvider
:param run_number: The run number
:param name: Condition type name
:return:
"""

run = db.get_run(run_number)
if not run:
print("Run number '{}' is not found in DB".format(run_number))
exit(1)

ct = db.get_condition_type(name)

result = db.get_condition(run, ct)
if not result:
return

condition = result
print(condition.value)


def show_run_conditions(db, run_number):
"""
:param db: RCDBProvider to database
:type db: RCDBProvider
:param run_number: The run number
:return:
"""

run = db.get_run(run_number)
if not run:
print("Run number {} is not found in DB".format(run_number))
exit(1)

conditions = db.session.query(Condition).join(Run).join(ConditionType) \
.order_by(asc(ConditionType.name)) \
.filter(Run.number == run_number) \
.all()

for condition in conditions:
condition_type = condition.type

if condition_type.value_type in [ConditionType.INT_FIELD,
ConditionType.BOOL_FIELD,
ConditionType.FLOAT_FIELD]:
print("{} = {}".format(condition_type.name, condition.value))
elif condition_type.value_type == ConditionType.STRING_FIELD:
print("{} = '{}'".format(condition_type.name, condition.value))
else:
# it is something big...
value = str(condition.value).replace('\n', "")[:50]
print("{} = ({}){}...".format(condition_type.name, condition_type.value_type, value))
File renamed without changes.
33 changes: 19 additions & 14 deletions rcdb_web/__init__.py → python/rcdb/web/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
from rcdb.alias import get_default_aliases_by_name
from rcdb.model import Run, RunPeriod
from flask import Flask, render_template, g, request, url_for
import rcdb
import os
from datetime import datetime

# configuration
from flask import Flask, render_template, g, request, url_for
from sqlalchemy.orm import subqueryload

import rcdb
from rcdb.alias import get_default_aliases_by_name
from rcdb.model import Run, RunPeriod

# register modules
from rcdb_web.runs.views import mod as runs_module
from rcdb_web.logs.views import mod as logs_module
from rcdb_web.files.views import mod as files_module
from rcdb_web.statistics.views import mod as statistics_module
from rcdb_web.conditions.views import mod as conditions_module
from rcdb_web.select_values.veiws import mod as select_values_module
from rcdb.web.modules import runs_module
from rcdb.web.modules import logs_module
from rcdb.web.modules import files_module
from rcdb.web.modules import statistics_module
from rcdb.web.modules import conditions_module
from rcdb.web.modules import select_values_module

DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
SQL_CONNECTION_STRING = "mysql+pymysql://rcdb@127.0.0.1/rcdb"

app = Flask(__name__)
app.config.from_object(__name__)
# Get the current directory
current_directory = os.path.dirname(os.path.abspath(__file__))
template_folder=os.path.join(current_directory, 'templates')
print(f"template_folder={template_folder}")
# Create Flask app with custom template folder
app = Flask(__name__, template_folder=template_folder)

app.config.from_object(__name__)

@app.before_request
def before_request():
Expand Down
6 changes: 6 additions & 0 deletions python/rcdb/web/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .conditions import mod as conditions_module
from .files import mod as files_module
from .logs import mod as logs_module
from .runs import mod as runs_module
from .select_values import mod as select_values_module
from .statistics import mod as statistics_module
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rcdb_web/logs/views.py → python/rcdb/web/modules/logs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, g
from sqlalchemy import desc
from rcdb.model import LogRecord
from rcdb_web.pagination import Pagination
from rcdb.web.pagination import Pagination

mod = Blueprint('logs', __name__, url_prefix='/logs')

Expand Down
11 changes: 5 additions & 6 deletions rcdb_web/runs/views.py → python/rcdb/web/modules/runs.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import json
import re
import sys
from time import mktime, time
from time import time

import datetime

from flask import Blueprint, request, render_template, flash, g, session, redirect, url_for, Response, jsonify
from flask import Blueprint, request, render_template, flash, g, redirect, url_for, Response, jsonify
# from werkzeug import check_password_hash, generate_password_hash
import rcdb
from collections import defaultdict
from rcdb import DefaultConditions
from rcdb.model import Run, Condition, ConditionType, ConfigurationFile
from rcdb.model import Run, ConfigurationFile
from rcdb.stopwatch import StopWatchTimer
from rcdb_web.pagination import Pagination
from rcdb.web.pagination import Pagination
from sqlalchemy import func
from sqlalchemy.orm import subqueryload, joinedload
from sqlalchemy.orm import subqueryload

mod = Blueprint('runs', __name__, url_prefix='/runs')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, request, render_template, flash, g, redirect, url_for
from rcdb.model import ConditionType, RunPeriod
from runs.views import _parse_run_range
from rcdb.web.modules.runs import _parse_run_range

mod = Blueprint('select_values', __name__, url_prefix='/select_values')

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf274da

Please sign in to comment.