diff --git a/.gitattributes b/.gitattributes index 44cd9358e6ed24dc5a5b875af0df1c87ca530eea..746b6a8c2efe7d537af5d851e4e131ae7e87d0ea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1770,7 +1770,23 @@ LCU/Firmware/tools/src/rsuctl3_reset -text LCU/Firmware/tools/src/view_images.sh -text LCU/MaintenanceDB/CMakeLists.txt -text LCU/MaintenanceDB/DBInterface/CMakeLists.txt -text -LCU/MaintenanceDB/DBInterface/dummy/dummy.py -text +LCU/MaintenanceDB/DBInterface/django_rest/__init__.py -text +LCU/MaintenanceDB/DBInterface/django_rest/create_db.sql -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/__init__.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/admin.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/apps.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/migrations/__init__.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/__init__.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/stationtest.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/models.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/serializers.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/tests.py -text +LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/views.py -text +LCU/MaintenanceDB/DBInterface/django_rest/requirements.txt -text +LCU/MaintenanceDB/DBInterface/django_rest/settings.py -text +LCU/MaintenanceDB/DBInterface/django_rest/urls.py -text +LCU/MaintenanceDB/DBInterface/django_rest/wsgi.py -text +LCU/MaintenanceDB/DBInterface/manage.py -text LCU/PPSTune/CMakeLists.txt -text LCU/PPSTune/MANIFEST.in -text LCU/PPSTune/README -text diff --git a/LCU/MaintenanceDB/DBInterface/CMakeLists.txt b/LCU/MaintenanceDB/DBInterface/CMakeLists.txt index efab479d1057c0bd9420754e09fdd850fdc41d52..8518f1ef91cebe87743c6db6c5f28c714aa3b183 100644 --- a/LCU/MaintenanceDB/DBInterface/CMakeLists.txt +++ b/LCU/MaintenanceDB/DBInterface/CMakeLists.txt @@ -3,8 +3,11 @@ lofar_package(DBInterface 1.0) # Install files matching regex pattern in current directory and below -install(DIRECTORY dummy +install(DIRECTORY django_rest DESTINATION ${CMAKE_INSTALL_PREFIX}/webserver USE_SOURCE_PERMISSIONS PATTERN ".svn" EXCLUDE) +install(FILES manage.py + DESTINATION ${CMAKE_INSTALL_PREFIX}/webserver) + diff --git a/LCU/MaintenanceDB/DBInterface/dummy/dummy.py b/LCU/MaintenanceDB/DBInterface/django_rest/__init__.py similarity index 100% rename from LCU/MaintenanceDB/DBInterface/dummy/dummy.py rename to LCU/MaintenanceDB/DBInterface/django_rest/__init__.py diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/create_db.sql b/LCU/MaintenanceDB/DBInterface/django_rest/create_db.sql new file mode 100755 index 0000000000000000000000000000000000000000..d61be16093b1a49504153680f7067e6f8533cc08 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/create_db.sql @@ -0,0 +1,9 @@ +CREATE DATABASE MonitoringDB; + +CREATE USER admin WITH PASSWORD 'fix-me'; + +ALTER ROLE admin SET client_encoding TO 'utf8'; +ALTER ROLE admin SET default_transaction_isolation TO 'read committed'; +ALTER ROLE admin SET timezone TO 'UTC'; + +GRANT ALL PRIVILEGES ON DATABASE MonitoringDB TO admin; diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/__init__.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/admin.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..b5b562e9fdaeed43669d04211854ca25ecff489d --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your model here. diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/apps.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..1f3a8775074729ef371ff1cb615a529486916924 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class MonitoringDbConfig(AppConfig): + name = 'monitoring_db' diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/migrations/__init__.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/__init__.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/stationtest.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/stationtest.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d03117797acd635e7cafa849e466bd07e49a57 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/model/stationtest.py @@ -0,0 +1,101 @@ +""" +In this file all the model regarding the stationtest output are collected +""" +from django.db import models + + +class StationTest(models.Model): + STATION_TYPES = ( + ('c', 'core'), + ('i', 'international'), + ('r', 'remote') + ) + id = models.AutoField(primary_key=True) + + station_name = models.CharField(max_length=6) + station_type = models.CharField(max_length=1, choices=STATION_TYPES) + + start_time = models.DateTimeField() + end_time = models.DateTimeField() + + performed_checks = models.CharField(max_length=50) + +class ComponentError(models.Model): + COMPONENT_TYPES = ( + ('RSP', 'RSP'), + ('TBB', 'Temporary Buffered Board'), + ('RCU', 'RCU'), + ('LBL', 'LBL'), + ('LBH', 'LBH'), + ('HBA', 'HBA'), + ) + ERROR_TYPES = ( + ('VERSION', 'Not expected hardware version'), + ('MEMORY', 'Memory error'), + ('BROKEN', 'Broken antennas connected to this RCU'), + ('NOSIGNAL', 'Signal not detected'), + ('TOOLOW', 'Average signal too low to perform test'), + ('DOWN', 'Antenna fallen down'), + ('RF_FAIL', 'Signal too high/low in tested subband'), + ('LOW_NOISE', 'Average signal in subband is low compared to the other subbands'), + ('HIGH_NOISE', 'Average signal in subband is high compared to the other subbands'), + ('JITTER', 'Jitter error'), + ('OSCILLATION', 'Oscillating antenna'), + ('SPURIOUS', 'Spurious signal found'), + ('P_SUMMATOR', 'Too low signals on all tiles'), + ('C_SUMMATOR', 'No communication with elements possible'), + ('SUMMATOR_NOISE', 'oscillating summator'), + ('TESTSIGNAL', 'Test signal used in RF test'), + ) + #test_signal = model.ForeignKey() + id = models.AutoField(primary_key=True) + component_id = models.IntegerField() + component_type = models.CharField(max_length=6, choices=COMPONENT_TYPES) + error_type = models.CharField(max_length=15, choices=ERROR_TYPES) + station_test_id = models.ForeignKey(StationTest, + related_name='component_errors', + on_delete=models.CASCADE) + sub_component_error_count = models.PositiveSmallIntegerField(default=0) + + +class TileError(models.Model): + id = models.AutoField(primary_key=True) + tile_id = models.SmallIntegerField(default=-1) + parent_component_error = models.ForeignKey(ComponentError, + related_name='tile_errors', + on_delete=models.CASCADE) + +class TileModemError(TileError): + communication_error = models.BooleanField() + + +class TileOscillatingError(TileError): + polarization = models.CharField(max_length=1) + + +class TileSpuriousError(TileError): + polarization = models.CharField(max_length=1) + + +class TileNoiseError(TileError): + polarization = models.CharField(max_length=1) + type = models.CharField(max_length=1) + # measured (lowest) highest mean value over all subbands + value = models.FloatField() + # difference between lowest and highest found mean values + diff = models.FloatField() + + +class TileJitterError(TileError): + polarization = models.CharField(max_length=1) + fluc = models.FloatField() + + +class TileRFFailure(TileError): + polarization = models.CharField(max_length=1) + measured_signal_nodelay = models.FloatField() + measured_signal_fulldelay = models.FloatField() + subband_used_nodelay = models.PositiveSmallIntegerField() + subband_used_fulldelay = models.PositiveSmallIntegerField() + reference_signal_nodelay = models.FloatField() + reference_signal_fulldelay = models.FloatField() diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/models.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/models.py new file mode 100644 index 0000000000000000000000000000000000000000..cccdd8ce23cec1497b559fcb1d174aac5781830f --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/models.py @@ -0,0 +1,4 @@ +from django.db import models + +# Create your model here. +from .model.stationtest import * diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/serializers.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/serializers.py new file mode 100644 index 0000000000000000000000000000000000000000..f427da2fdba80ae5f5349050a4fb6091f91f64aa --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/serializers.py @@ -0,0 +1,4 @@ + + +from .model import * +from rest_framework import serializers diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/tests.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/views.py b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/views.py new file mode 100644 index 0000000000000000000000000000000000000000..91ea44a218fbd2f408430959283f0419c921093e --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/monitoring_db/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/requirements.txt b/LCU/MaintenanceDB/DBInterface/django_rest/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..b906ea9d706caa292ebc0679b7ff999a870e7131 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/requirements.txt @@ -0,0 +1,3 @@ +django +psycopg2-binary +djangorestframework diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/settings.py b/LCU/MaintenanceDB/DBInterface/django_rest/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..1da4d84c0d76dc181955ae548ef8b7bf3ddfaea8 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for django_rest project. + +Generated by 'django-admin startproject' using Django 2.0.4. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'x)5=9*2a&)32h-loh@rlt_9eyw%t$-fqao*#1j2gh^7=^bnjyy' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'rest_framework' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'django_rest.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'django_rest.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'monitoringdb', + 'USER': 'admin', + 'PASSWORD': 'fix-me', + 'HOST': 'localhost', + 'PORT': '', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/urls.py b/LCU/MaintenanceDB/DBInterface/django_rest/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..bc4d624fc10457bda9576ef92bdf06b4bdc8d253 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/urls.py @@ -0,0 +1,21 @@ +"""django_rest URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/LCU/MaintenanceDB/DBInterface/django_rest/wsgi.py b/LCU/MaintenanceDB/DBInterface/django_rest/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..ff8a52d369d52a17870b4a4039a8ad93b9d2cb10 --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/django_rest/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for django_rest project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_rest.settings") + +application = get_wsgi_application() diff --git a/LCU/MaintenanceDB/DBInterface/manage.py b/LCU/MaintenanceDB/DBInterface/manage.py new file mode 100755 index 0000000000000000000000000000000000000000..f2a5f40d45f9aeb129205336711e50429848f24c --- /dev/null +++ b/LCU/MaintenanceDB/DBInterface/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_rest.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv)