remove django app
This commit is contained in:
parent
0d5507b0f9
commit
43d968bd4c
@ -1,16 +0,0 @@
|
||||
"""
|
||||
ASGI config for benchtopdevices project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'benchtopdevices.settings')
|
||||
|
||||
application = get_asgi_application()
|
@ -1,134 +0,0 @@
|
||||
"""
|
||||
Django settings for benchtopdevices project.
|
||||
|
||||
Generated by 'django-admin startproject' using Django 4.2.3.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/4.2/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/4.2/ref/settings/
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = 'django-insecure-=$1$b*-dgj6+@&-=yl*xsw@if=t%em(u_-i_^p4+-k0^nsg=--'
|
||||
|
||||
# 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',
|
||||
'debug_toolbar',
|
||||
'sheets',
|
||||
'rest_framework',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||
'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 = 'benchtopdevices.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 = 'benchtopdevices.wsgi.application'
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/4.2/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/4.2/topics/i18n/
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'America/New_York'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/4.2/howto/static-files/
|
||||
|
||||
STATIC_URL = 'static/'
|
||||
|
||||
# Default primary key field type
|
||||
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
INTERNAL_IPS = [
|
||||
# ...
|
||||
"127.0.0.1",
|
||||
# ...
|
||||
]
|
@ -1,24 +0,0 @@
|
||||
"""
|
||||
URL configuration for benchtopdevices project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/4.2/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, include
|
||||
|
||||
urlpatterns = [
|
||||
path('', include('sheets.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path("__debug__/", include("debug_toolbar.urls")),
|
||||
]
|
@ -1,16 +0,0 @@
|
||||
"""
|
||||
WSGI config for benchtopdevices 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/4.2/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'benchtopdevices.settings')
|
||||
|
||||
application = get_wsgi_application()
|
@ -1,22 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'benchtopdevices.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)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,4 +0,0 @@
|
||||
django
|
||||
psycopg2-binary
|
||||
django-debug-toolbar
|
||||
django-rest-framework
|
@ -1,10 +0,0 @@
|
||||
from django.contrib import admin
|
||||
from .models import (
|
||||
Sheet
|
||||
)
|
||||
|
||||
|
||||
class SheetAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
admin.site.register(Sheet, SheetAdmin)
|
@ -1,6 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SheetsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'sheets'
|
@ -1,67 +0,0 @@
|
||||
from django import forms
|
||||
from django.forms.widgets import ClearableFileInput
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import Sheet
|
||||
|
||||
|
||||
class SheetForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Sheet
|
||||
fields = [
|
||||
"customer_name",
|
||||
"onsite_cal",
|
||||
"control_doc",
|
||||
"technician",
|
||||
|
||||
"instrument_model",
|
||||
"instrument_calibration_date",
|
||||
"instrument_calibration_due_date",
|
||||
"serial_number",
|
||||
"channel",
|
||||
"transducer_model",
|
||||
"transducer_span",
|
||||
|
||||
"calibration_serial",
|
||||
"calibration_model",
|
||||
"calibration_date",
|
||||
"calibration_due_date",
|
||||
"calibration_cert_id",
|
||||
|
||||
"accuracy",
|
||||
"barometric_pressure",
|
||||
"temperature",
|
||||
"humidity",
|
||||
"report_type",
|
||||
"transducer_type",
|
||||
|
||||
"as_found",
|
||||
"as_left",
|
||||
"both",
|
||||
]
|
||||
|
||||
widgets = {
|
||||
"accuracy": forms.NumberInput(attrs={'step': 0.01}),
|
||||
"barometric_pressure": forms.NumberInput(attrs={'step': 0.01, 'max': 1100, 'min': 800}),
|
||||
"temperature": forms.NumberInput(attrs={'step': 0.01, 'max': 1000.0, 'min': -459.67}),
|
||||
"humidity": forms.NumberInput(attrs={'step': 0.01, 'max': 100.0, 'min': 0.0}),
|
||||
"calibration_date": forms.SelectDateWidget(years=range(2020, 2030)),
|
||||
"calibration_due_date": forms.SelectDateWidget(years=range(2020, 2030)),
|
||||
"instrument_calibration_date": forms.SelectDateWidget(years=range(2020, 2030)),
|
||||
"instrument_calibration_due_date": forms.SelectDateWidget(years=range(2020, 2030)),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SheetForm, self).__init__(*args, **kwargs)
|
||||
|
||||
for name, field in self.fields.items():
|
||||
# add v-model to each model field
|
||||
if isinstance(field, forms.fields.FileField):
|
||||
field.widget.attrs.update(
|
||||
{
|
||||
'v-on:change': f"change_{name}",
|
||||
'v-if': f"show_{name}"
|
||||
})
|
||||
else:
|
||||
field.widget.attrs.update({'v-model': name})
|
@ -1,38 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-09-18 17:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Sheet',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('customer_name', models.CharField(max_length=256)),
|
||||
('customer_address', models.CharField(max_length=256)),
|
||||
('serial_number', models.CharField(max_length=256)),
|
||||
('accuracy', models.FloatField()),
|
||||
('barometric_pressure', models.FloatField()),
|
||||
('temperature', models.FloatField()),
|
||||
('humidity', models.FloatField()),
|
||||
('report_type', models.CharField(choices=[('TV', 'Transducer Verify'), ('HC', 'Hardware Calibration')], max_length=256)),
|
||||
('as_found', models.FileField(blank=True, upload_to='')),
|
||||
('as_left', models.FileField(blank=True, upload_to='')),
|
||||
('both', models.FileField(blank=True, upload_to='')),
|
||||
('calibration_cert_id', models.CharField(default=0, max_length=100)),
|
||||
('calibration_date', models.DateField(default=0)),
|
||||
('calibration_due_date', models.DateField(default=0)),
|
||||
('calibration_model', models.CharField(default=0, max_length=100)),
|
||||
('calibration_serial', models.CharField(default=0, max_length=100)),
|
||||
('channel', models.CharField(default=0, max_length=256)),
|
||||
('instrument_model', models.CharField(default=0, max_length=256)),
|
||||
('transducer_model', models.CharField(default=0, max_length=256)),
|
||||
('transducer_span', models.CharField(default=0, max_length=256)),
|
||||
],
|
||||
),
|
||||
]
|
@ -1,58 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-09-18 17:03
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sheets', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='calibration_cert_id',
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='calibration_date',
|
||||
field=models.DateField(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='calibration_due_date',
|
||||
field=models.DateField(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='calibration_model',
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='calibration_serial',
|
||||
field=models.CharField(max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='channel',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='instrument_model',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='transducer_model',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sheet',
|
||||
name='transducer_span',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
]
|
@ -1,34 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-09-18 17:13
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sheets', '0002_alter_sheet_calibration_cert_id_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='sheet',
|
||||
name='customer_address',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='control_doc',
|
||||
field=models.CharField(default=0, max_length=256),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='onsite_cal',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='technician',
|
||||
field=models.CharField(default=0, max_length=256),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -1,18 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-05 03:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sheets', '0003_remove_sheet_customer_address_sheet_control_doc_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='kind',
|
||||
field=models.CharField(blank=True, choices=[('p', 'Pressure Transducer'), ('f', 'Flow Transducer')], max_length=256),
|
||||
),
|
||||
]
|
@ -1,22 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-05 03:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sheets', '0004_sheet_kind'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='sheet',
|
||||
name='kind',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='transducer_type',
|
||||
field=models.CharField(blank=True, choices=[('Pressure', 'Pressure Transducer'), ('Flow', 'Flow Transducer')], max_length=256),
|
||||
),
|
||||
]
|
@ -1,26 +0,0 @@
|
||||
# Generated by Django 4.2.5 on 2023-10-05 03:42
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sheets', '0005_remove_sheet_kind_sheet_transducer_type'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='instrument_calibration_date',
|
||||
field=models.DateField(default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='sheet',
|
||||
name='instrument_calibration_due_date',
|
||||
field=models.DateField(default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -1,54 +0,0 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class Sheet(models.Model):
|
||||
instrument_model = models.CharField(max_length=256)
|
||||
instrument_calibration_date = models.DateField()
|
||||
instrument_calibration_due_date = models.DateField()
|
||||
serial_number = models.CharField(max_length=256)
|
||||
channel = models.CharField(max_length=256)
|
||||
transducer_model = models.CharField(max_length=256)
|
||||
transducer_span = models.CharField(max_length=256)
|
||||
|
||||
customer_name = models.CharField(max_length=256)
|
||||
onsite_cal = models.BooleanField(default=False)
|
||||
control_doc = models.CharField(max_length=256)
|
||||
technician = models.CharField(max_length=256)
|
||||
|
||||
accuracy = models.FloatField()
|
||||
|
||||
barometric_pressure = models.FloatField()
|
||||
temperature = models.FloatField()
|
||||
humidity = models.FloatField()
|
||||
|
||||
calibration_serial = models.CharField(max_length=100)
|
||||
calibration_model = models.CharField(max_length=100)
|
||||
calibration_date = models.DateField()
|
||||
calibration_due_date = models.DateField()
|
||||
calibration_cert_id = models.CharField(max_length=100)
|
||||
|
||||
CHOICES = [
|
||||
('TV', _('Transducer Verify')),
|
||||
('HC', _('Hardware Calibration'))
|
||||
]
|
||||
|
||||
report_type = models.CharField(
|
||||
max_length=256,
|
||||
choices=CHOICES,
|
||||
)
|
||||
|
||||
TRANSDUCER_TYPES = [
|
||||
('Pressure', _('Pressure Transducer')),
|
||||
('Flow', _('Flow Transducer'))
|
||||
]
|
||||
|
||||
transducer_type = models.CharField(
|
||||
max_length=256,
|
||||
choices=TRANSDUCER_TYPES,
|
||||
blank=True
|
||||
)
|
||||
|
||||
as_found = models.FileField(blank=True)
|
||||
as_left = models.FileField(blank=True)
|
||||
both = models.FileField(blank=True)
|
@ -1,2 +0,0 @@
|
||||
from .hardware import parse_hardware_calibration
|
||||
from .transducer import parse_transducer
|
@ -1,68 +0,0 @@
|
||||
import re
|
||||
|
||||
|
||||
def parse_instrument_info(text):
|
||||
instrument_info = {}
|
||||
# Regex pattern for key-value pairs in the instrument info section
|
||||
for line in text.split("\n")[2:]:
|
||||
if line:
|
||||
key, value = re.sub(r"\s\s+", "`", line.strip()).split("`")
|
||||
instrument_info[key.strip()] = value.strip()
|
||||
return instrument_info
|
||||
|
||||
|
||||
def parse_ports(text):
|
||||
text = f"{text}\n\n" # ensure extra newline to match on
|
||||
pattern = r"(Test Port \d)"
|
||||
matches = re.split(pattern, text)[1:]
|
||||
m = dict(list(zip(matches[0::2], matches[1::2])))
|
||||
calibration_data = {}
|
||||
for port, calibration in m.items():
|
||||
calibration_data[port] = parse_calibration_data(calibration)
|
||||
return calibration_data
|
||||
|
||||
|
||||
KEEP = {
|
||||
"Mass Flow Trans": ("Instrument Flow", "Master Reading"),
|
||||
"Pressure Transducer": ("Instrument Pressure", "Master Value"),
|
||||
}
|
||||
|
||||
|
||||
def parse_calibration_data(text):
|
||||
# Regex pattern for each block in the calibration data section per Port
|
||||
pattern = r"(Mass Flow Trans|Pressure Transducer)\n(.+?)\n\n"
|
||||
matches = re.findall(pattern, text, re.DOTALL)
|
||||
calibration_data = {}
|
||||
for block_title, block_content in matches:
|
||||
lines = block_content.strip().split("\n")
|
||||
lines.pop(0) # Go away =======
|
||||
device_name = lines.pop(0).strip().split(None, 1)[-1].strip()
|
||||
device_data = {"name": device_name}
|
||||
for line in lines:
|
||||
key, value = re.sub(r"\s\s+", "`", line.strip()).split("`")
|
||||
# Only keep the fields we want
|
||||
for start in KEEP[block_title]:
|
||||
key = key.strip()
|
||||
if key.startswith(start):
|
||||
device_data[key] = value.strip()
|
||||
calibration_data[block_title] = device_data
|
||||
return calibration_data
|
||||
|
||||
|
||||
def parse_hardware_calibration(content, accuracy):
|
||||
# Split the content into instrument info and calibration data sections
|
||||
info_section, calibration_section = content.split(
|
||||
"|| Hardware Calibration Report ||"
|
||||
)
|
||||
|
||||
instrument_info = parse_instrument_info(info_section)
|
||||
calibration_data = parse_ports(calibration_section)
|
||||
|
||||
return {"instrument": instrument_info, "calibration": calibration_data}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
file_path = "./hardware_calibration.txt" # Replace with the actual file path
|
||||
with open(file_path, "r") as file:
|
||||
content = file.read()
|
||||
data = parse_file(file_path)
|
@ -1,129 +0,0 @@
|
||||
import re
|
||||
import json
|
||||
|
||||
def in_range(index, value, master_values):
|
||||
return (
|
||||
master_values[index]["Low Limit"] <= value <= master_values[index]["High Limit"]
|
||||
)
|
||||
|
||||
|
||||
def delta(index, value, master_values):
|
||||
return abs(master_values[index]["Low Limit"] - value)
|
||||
|
||||
|
||||
def parse_transducer(content, accuracy):
|
||||
accuracy = accuracy/100.0 # Comes in as Percent
|
||||
transducer_data = []
|
||||
|
||||
# Split the content into sections based on the blank line
|
||||
sections = content.strip().split("\n\n")
|
||||
|
||||
for section in sections:
|
||||
# Split each section into lines
|
||||
lines = section.strip().split("\n")
|
||||
lines = [
|
||||
line.strip()
|
||||
for line in lines
|
||||
if not line.startswith("==") and line != "|| Transducer Verify Report ||"
|
||||
]
|
||||
lines.pop(0)
|
||||
|
||||
# Extract the Transducer number and Transducer type
|
||||
transducer_line = lines.pop(0).strip()
|
||||
_, transducer_name, part_number = transducer_line.split(None, 2)
|
||||
|
||||
# Get part number and values
|
||||
value = None
|
||||
unit = None
|
||||
transducer_type = None
|
||||
if part_number != "Custom":
|
||||
value = part_number.split()[-1]
|
||||
part_number = part_number.split()[1]
|
||||
if match := re.match(r"([0-9]+)([A-Z]+)", value, re.I):
|
||||
value, unit = match.groups()
|
||||
value = int(value)
|
||||
if unit == "SCCM":
|
||||
transducer_type = "Flow"
|
||||
if unit == "PSIA":
|
||||
transducer_type = "Pressure"
|
||||
|
||||
# Create a dictionary to store the data for each transducer
|
||||
transducer_info = {
|
||||
"Accuracy": accuracy,
|
||||
"Part Number": part_number,
|
||||
"Value": value,
|
||||
"Unit": unit,
|
||||
"Limit ABS": int(value * accuracy * 1000),
|
||||
"Transducer Name": transducer_name,
|
||||
"Transducer Type": transducer_type,
|
||||
"Gauge Reading": [],
|
||||
"Master Value": [],
|
||||
"Verify Date": "",
|
||||
"Verify Time": "",
|
||||
}
|
||||
|
||||
# Extract other information for the transducer
|
||||
for line in lines:
|
||||
key, value = re.sub(r"\s\s+", ",", line.strip()).split(",")
|
||||
if "Verify Date" in key:
|
||||
transducer_info["Verify Date"] = value
|
||||
continue
|
||||
elif "Verify Time" in key:
|
||||
transducer_info["Verify Time"] = value
|
||||
continue
|
||||
|
||||
# Toss anything else where it belongs
|
||||
key = re.match(r"(.*)\W(\d)", key)[1]
|
||||
if key in transducer_info or f"Instrument {transducer_type}" in key:
|
||||
value = int(float(value.split()[0])*1000)
|
||||
# special case Master to get the limits
|
||||
if "Master" in key:
|
||||
hi = value + transducer_info["Limit ABS"]
|
||||
lo = value - transducer_info["Limit ABS"]
|
||||
transducer_info[key].append(
|
||||
{
|
||||
"Low Limit": int(lo),
|
||||
"Master Value": value,
|
||||
"High Limit": int(hi),
|
||||
}
|
||||
)
|
||||
# Turn both Instrument Pressure and Instrument Flow to Gauge Reading
|
||||
elif f"Instrument {transducer_type}" in key:
|
||||
transducer_info["Gauge Reading"].append(value)
|
||||
else:
|
||||
transducer_info[key].append(value)
|
||||
|
||||
# Once we have the readings, and master values, we can do the math
|
||||
transducer_info["Gauge Reading"] = [
|
||||
{
|
||||
"Value": v,
|
||||
"In Range": in_range(idx, v, transducer_info["Master Value"]),
|
||||
"Delta": delta(idx, v, transducer_info["Master Value"])
|
||||
}
|
||||
for idx, v in enumerate(transducer_info["Gauge Reading"])
|
||||
]
|
||||
|
||||
transducer_data.append(transducer_info)
|
||||
|
||||
return transducer_data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from pprint import pprint
|
||||
file_path = "./transducer_verify.txt"
|
||||
with open(file_path, "r") as file:
|
||||
output = {
|
||||
"Instrument": "CTS0JODFDASH",
|
||||
"Customer Name": "Anthony Souza",
|
||||
"Customer Address": "PO Box 357, West Chesterfield, NH 03466",
|
||||
"Control Number": "123123",
|
||||
"Serial Number": "123313",
|
||||
"Accuracy": 0.5,
|
||||
"Barometric Pressure": 1013.25,
|
||||
"Temperature": 50.3,
|
||||
"Humidity": 27,
|
||||
"Transducers": parse_transducer(file.read(), 0.5)
|
||||
}
|
||||
print(json.dumps(output).replace('"', '""'))
|
||||
pprint(output)
|
||||
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,6 +0,0 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.upload_file, name = 'upload'),
|
||||
]
|
@ -1,33 +0,0 @@
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.shortcuts import render
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from .forms import SheetForm, SheetForm
|
||||
from .parsers import parse_transducer, parse_hardware_calibration
|
||||
|
||||
|
||||
def upload_file(request):
|
||||
if request.method == "POST":
|
||||
f = SheetForm(request.POST, request.FILES)
|
||||
if f.is_valid():
|
||||
data = f.clean()
|
||||
as_found = request.FILES.get('as_found')
|
||||
as_left = request.FILES.get('as_left')
|
||||
both = request.FILES.get('both')
|
||||
if both:
|
||||
if data['report_type'] == "TV":
|
||||
tv = parse_transducer(both.read().decode(), data['accuracy'])
|
||||
f.transducer_type = tv["Transducer Type"]
|
||||
else:
|
||||
hc = parse_hardware_calibration(both.read().decode(), data['accuracy'])
|
||||
elif as_found and as_left:
|
||||
# TODO: DO THIS
|
||||
pass
|
||||
else:
|
||||
raise ValidationError("Please provide proper files")
|
||||
f.save()
|
||||
breakpoint()
|
||||
return HttpResponseRedirect("/")
|
||||
else:
|
||||
form = SheetForm()
|
||||
return HttpResponse("hi")
|
@ -1,85 +0,0 @@
|
||||
|| Transducer Verify Report ||
|
||||
TRANSDUCER1
|
||||
===============================================================
|
||||
Transducer 1 CTS D34-442 115PSIA
|
||||
Setpoint Pressure 1 0.000 psig
|
||||
Setpoint Pressure 2 20.000 psig
|
||||
Setpoint Pressure 3 40.000 psig
|
||||
Setpoint Pressure 4 60.000 psig
|
||||
Setpoint Pressure 5 80.000 psig
|
||||
Setpoint Pressure 6 100.000 psig
|
||||
Instrument Pressure 1 0.000 psig
|
||||
Instrument Pressure 2 20.002 psig
|
||||
Instrument Pressure 3 39.997 psig
|
||||
Instrument Pressure 4 60.010 psig
|
||||
Instrument Pressure 5 80.001 psig
|
||||
Instrument Pressure 6 100.002 psig
|
||||
Master Value 1 0.000 psig
|
||||
Master Value 2 20.000 psig
|
||||
Master Value 3 40.000 psig
|
||||
Master Value 4 60.000 psig
|
||||
Master Value 5 80.000 psig
|
||||
Master Value 6 100.000 psig
|
||||
Verify Date 07/20/22
|
||||
Verify Time 11:20:26
|
||||
|
||||
TRANSDUCER2
|
||||
===============================================================
|
||||
Transducer 2 CTS A12-221 250SCCM
|
||||
Setpoint Pressure 1 20.000 psig
|
||||
Setpoint Pressure 2 20.000 psig
|
||||
Setpoint Pressure 3 20.000 psig
|
||||
Setpoint Pressure 4 20.000 psig
|
||||
Setpoint Pressure 5 20.000 psig
|
||||
Setpoint Pressure 6 20.000 psig
|
||||
Setpoint Pressure 7 20.000 psig
|
||||
Setpoint Pressure 8 20.000 psig
|
||||
Setpoint Pressure 9 20.000 psig
|
||||
Setpoint Pressure 10 20.000 psig
|
||||
Setpoint Pressure 11 20.000 psig
|
||||
Instrument Pressure 1 20.154 psig
|
||||
Instrument Pressure 2 20.153 psig
|
||||
Instrument Pressure 3 20.152 psig
|
||||
Instrument Pressure 4 20.150 psig
|
||||
Instrument Pressure 5 20.148 psig
|
||||
Instrument Pressure 6 20.145 psig
|
||||
Instrument Pressure 7 20.144 psig
|
||||
Instrument Pressure 8 20.141 psig
|
||||
Instrument Pressure 9 20.139 psig
|
||||
Instrument Pressure 10 20.138 psig
|
||||
Instrument Pressure 11 20.136 psig
|
||||
Instrument Flow 1 -0.082 sccm
|
||||
Instrument Flow 2 24.802 sccm
|
||||
Instrument Flow 3 49.664 sccm
|
||||
Instrument Flow 4 74.836 sccm
|
||||
Instrument Flow 5 99.416 sccm
|
||||
Instrument Flow 6 125.289 sccm
|
||||
Instrument Flow 7 150.205 sccm
|
||||
Instrument Flow 8 175.290 sccm
|
||||
Instrument Flow 9 200.165 sccm
|
||||
Instrument Flow 10 224.748 sccm
|
||||
Instrument Flow 11 249.825 sccm
|
||||
Master Reading 1 0.000 sccm
|
||||
Master Reading 2 25.000 sccm
|
||||
Master Reading 3 50.000 sccm
|
||||
Master Reading 4 75.000 sccm
|
||||
Master Reading 5 100.000 sccm
|
||||
Master Reading 6 125.000 sccm
|
||||
Master Reading 7 150.000 sccm
|
||||
Master Reading 8 175.000 sccm
|
||||
Master Reading 9 200.000 sccm
|
||||
Master Reading 10 225.000 sccm
|
||||
Master Reading 11 250.000 sccm
|
||||
Master Value 1 0.000 sccm
|
||||
Master Value 2 25.000 sccm
|
||||
Master Value 3 50.000 sccm
|
||||
Master Value 4 75.000 sccm
|
||||
Master Value 5 100.000 sccm
|
||||
Master Value 6 125.000 sccm
|
||||
Master Value 7 150.000 sccm
|
||||
Master Value 8 175.000 sccm
|
||||
Master Value 9 200.000 sccm
|
||||
Master Value 10 225.000 sccm
|
||||
Master Value 11 250.000 sccm
|
||||
Verify Date 07/15/21
|
||||
Verify Time 14:55:10
|
Loading…
Reference in New Issue
Block a user