Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Starting merging first prototype of runhistos view #5

Merged
merged 6 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lumisections/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Lumisection

# Register your models here.
admin.site.register(Lumisection)
6 changes: 6 additions & 0 deletions lumisections/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class LumisectionsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'lumisections'
39 changes: 39 additions & 0 deletions lumisections/management/commands/extract_lumisections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from django.core.management.base import BaseCommand

from runs.models import Run
from lumisections.models import Lumisection

# https://betterprogramming.pub/3-techniques-for-importing-large-csv-files-into-a-django-app-2b6e5e47dba0
import pandas as pd

class Command(BaseCommand):
help = "Extracts lumisections from files"

def add_arguments(self, parser):
parser.add_argument("file_path", type=str)

def handle(self, *args, **options):
file_path = options["file_path"]

df = pd.read_csv(file_path)

lumisections = []

for index, row in df.iterrows():
run_number = row["fromrun"]
lumi_number = row["fromlumi"]
#print(run_number, lumi_number)

run, _ = Run.objects.get_or_create(run_number=run_number)

lumisection = Lumisection(
run_number = run,
ls_number = lumi_number,
)

lumisections.append(lumisection)

Lumisection.objects.bulk_create(lumisections)
print(f'lumisections successfully added!')


11 changes: 11 additions & 0 deletions lumisections/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.db import models
from runs.models import Run

# Create your models here.
class Lumisection(models.Model):
ls_number = models.IntegerField()
run_number = models.ForeignKey(Run, on_delete=models.CASCADE)
date = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"run {self.run_number.run_number} / lumisection {self.ls_number}"
3 changes: 3 additions & 0 deletions lumisections/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
18 changes: 11 additions & 7 deletions mlp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os

from pathlib import Path
from decouple import config

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
Expand Down Expand Up @@ -53,6 +51,7 @@

'runs.apps.RunsConfig',
'run_histos.apps.RunHistosConfig',
'lumisections',
]

MIDDLEWARE = [
Expand All @@ -71,7 +70,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -132,8 +131,13 @@
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'
#STATICFILES_DIRS = (os.path.join(BASE_DIR, 'home/static'),)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS = [ BASE_DIR / 'static_project' ]

STATIC_ROOT = BASE_DIR / 'static_cdn/static_root'

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'static_cdn/media_root'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
2 changes: 2 additions & 0 deletions mlp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
urlpatterns = [
path("", include("home.urls")),
path("datasets/", include("datasets.urls")),
path("runs/", include("runs.urls")),
path("run_histos/", include("run_histos.urls")),
path('admin/', admin.site.urls),
]
Loading