Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View new sensor models #158

Merged
merged 26 commits into from Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
364bc7c
1) Updated views/sensor.py to refelct new database schema
Mar 18, 2020
edd9837
Merge branch 'frontend-team' into ray_develop
Mar 19, 2020
ca69ea8
Updated formatting
Mar 19, 2020
55b893b
Fixed input validation for "Add Sensor"
Mar 19, 2020
a04f253
Updated sensor models in mercury/models.py
Mar 19, 2020
299c668
Modified how sensor is being created. Code needs to be tested.
Mar 19, 2020
b8875ed
Changed all imports for AG models from mercury/models.py to ag_data.m…
dandipietrantonio Mar 20, 2020
57dc845
soled merge conflict
dandipietrantonio Mar 20, 2020
992b73f
POST for adding type is working, now working on adding sensor
dandipietrantonio Mar 20, 2020
647e05f
Able to add sensors but the displaying breaks, need to fix
dandipietrantonio Mar 20, 2020
e6f1267
Creating new sensor and sensor types working
dandipietrantonio Mar 21, 2020
802a2dd
Delete sensors and delete sensor types both working, moving on to edi…
dandipietrantonio Mar 21, 2020
1eba0a6
Can now edit existing sensors, still need to fix a few bugs, add tran…
dandipietrantonio Mar 21, 2020
176709c
Adding, updating, deleting both sensors and sensor types completed, j…
dandipietrantonio Mar 22, 2020
e627e26
forgot to add migration to git
dandipietrantonio Mar 22, 2020
6ca0145
Added some tests to sensors view, still needs more
dandipietrantonio Mar 22, 2020
ffed11d
Resolve merge conflict - not removing old models yet, saving this for…
daisycrego Mar 23, 2020
9b22456
Sync branch with frontend-team. Get grafana changes into branch.
daisycrego Mar 23, 2020
3f2104e
Added tests to sensor view
dandipietrantonio Mar 23, 2020
6ec0af6
Modify GF config post view to create a dashboard and datasource each …
daisycrego Mar 23, 2020
274069b
Getting grafana functionality into configure sensors view.
daisycrego Mar 23, 2020
e986fb4
Fixed formatting for tests
dandipietrantonio Mar 23, 2020
b1c999c
Fix migrations files to handle recent merge.
daisycrego Mar 23, 2020
9c65299
Black and flake8.
daisycrego Mar 23, 2020
c079965
Add AGEvent model back into the db, because it was being referenced i…
daisycrego Mar 23, 2020
63e36c0
Add reference to AGEvent model back into test which was failing.
daisycrego Mar 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions mercury/migrations/0012_auto_20200320_1735.py
@@ -0,0 +1,30 @@
# Generated by Django 2.2.11 on 2020-03-20 17:35

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mercury', '0011_merge_20200314_0111'),
]

operations = [
migrations.RemoveField(
model_name='agmeasurement',
name='measurement_event',
),
migrations.RemoveField(
model_name='agmeasurement',
name='measurement_sensor',
),
migrations.DeleteModel(
name='AGEvent',
),
migrations.DeleteModel(
name='AGMeasurement',
),
migrations.DeleteModel(
name='AGSensor',
),
]
14 changes: 14 additions & 0 deletions mercury/migrations/0016_merge_20200323_1532.py
@@ -0,0 +1,14 @@
# Generated by Django 2.2.6 on 2020-03-23 15:32

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mercury', '0015_gfconfig_gf_db_grafana_name'),
('mercury', '0012_auto_20200320_1735'),
]

operations = [
]
25 changes: 25 additions & 0 deletions mercury/migrations/0017_agevent.py
@@ -0,0 +1,25 @@
# Generated by Django 2.2.6 on 2020-03-23 15:55

from django.db import migrations, models
import django.utils.timezone
import uuid


class Migration(migrations.Migration):

dependencies = [
('mercury', '0016_merge_20200323_1532'),
]

operations = [
migrations.CreateModel(
name='AGEvent',
fields=[
('event_uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('event_name', models.CharField(blank=True, max_length=40)),
('event_date', models.DateTimeField(default=django.utils.timezone.now)),
('event_description', models.CharField(blank=True, max_length=100)),
('event_location', models.CharField(blank=True, max_length=100)),
],
),
]
46 changes: 12 additions & 34 deletions mercury/models.py
@@ -1,42 +1,8 @@
from django.db import models
from django.contrib.postgres.fields import JSONField
import uuid
from django.utils import timezone


class AGEvent(models.Model):
"""This model stores the information about events. When a new event is created,
a UUID4-typed event_uuid will be assigned to this event and also store the current
date for this event. """

event_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
event_name = models.CharField(max_length=40, blank=True)
event_date = models.DateTimeField(default=timezone.now)
event_description = models.CharField(max_length=100, null=False, blank=True)
event_location = models.CharField(max_length=100, null=False, blank=True)


class AGSensor(models.Model):
sensor_id = models.AutoField(primary_key=True)
sensor_name = models.CharField(max_length=1024, blank=True)
sensor_processing_formula = models.IntegerField(default=0, null=False)
sensor_format = JSONField()


class AGMeasurement(models.Model):
measurement_uuid = models.UUIDField(
primary_key=True, default=uuid.uuid4, editable=False
)
measurement_timestamp = models.DateTimeField(default=timezone.now, blank=False)
measurement_event = models.ForeignKey(
AGEvent, on_delete=models.CASCADE, blank=False, null=False
)
measurement_sensor = models.ForeignKey(
AGSensor, on_delete=models.CASCADE, blank=False, null=False
)
measurement_value = JSONField()


class GFConfig(models.Model):
"""
Grafana configs
Expand All @@ -56,6 +22,18 @@ class GFConfig(models.Model):
gf_current = models.BooleanField(default=False, blank=True)


class AGEvent(models.Model):
"""This model stores the information about events. When a new event is created,
a UUID4-typed event_uuid will be assigned to this event and also store the current
date for this event. """

event_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
event_name = models.CharField(max_length=40, blank=True)
event_date = models.DateTimeField(default=timezone.now)
event_description = models.CharField(max_length=100, null=False, blank=True)
event_location = models.CharField(max_length=100, null=False, blank=True)


class TemperatureSensor(models.Model):
"""This model represents the Temperature sensor that we expect to
be potentially available in the future in the NYU Motorsports
Expand Down
186 changes: 132 additions & 54 deletions mercury/static/mercury/js/sensor.js
@@ -1,51 +1,22 @@
function addRow(){
var sensorList, field_name_li, field_type_li, field_name_input, field_type_select,
float_option, string_option, bool_option;

fields = document.getElementById("field-list");
// Make field name input
field_name_input = document.createElement("input");
field_name_input.setAttribute("type","text");
field_name_input.setAttribute("name","field-name");
field_name_input.setAttribute("class","inline-block-child");
fields.appendChild(field_name_input);

//Make field type
field_type_select = document.createElement("select");
field_type_select.setAttribute("name", "field-type");
field_type_select.setAttribute("class", "inline-block-child");

float_option = document.createElement("option");
float_option.setAttribute("value", "float");
float_option.appendChild(document.createTextNode("Float"));
field_type_select.appendChild(float_option);

string_option = document.createElement("option");
string_option.setAttribute("value", "string");
string_option.appendChild(document.createTextNode("String"));
field_type_select.appendChild(string_option);

bool_option = document.createElement("option");
bool_option.setAttribute("value", "bool");
bool_option.appendChild(document.createTextNode("Boolean"));
field_type_select.appendChild(bool_option);

fields.appendChild(field_type_select);

// Make unit input
unit_input = document.createElement("input");
unit_input.setAttribute("type","text");
unit_input.setAttribute("name","field-unit")
unit_input.setAttribute("class", "inline-block-child");
fields.appendChild(unit_input);

var hr = document.createElement('hr');
fields.appendChild(hr);
var table = document.getElementById("new-type-table");
var rowCount = table.rows.length;
var colCount = table.rows[0].cells.length;
var newRow = table.insertRow(rowCount);
for(var i=0; i<colCount; i++){
var newCell = newRow.insertCell(i);
/* set new cell to be same as cell in first data (non-header) row */
newCell.innerHTML = table.rows[1].cells[i].innerHTML
}
table.rows[rowCount].cells[0].innerHTML =rowCount
}

var add_field_button = document.getElementById("addfieldbutton");
add_field_button.onclick = function() {
addRow();
function deleteRow() {
var table = document.getElementById("new-type-table");
var rowCount = table.rows.length;
if (rowCount > 2){
table.deleteRow(rowCount-1)
}
}

/*
Expand All @@ -54,32 +25,139 @@ selectView displays the correct view of the "Add or Modify Sensors" page
-if a user submits a new sensor which posts and reloads page, then the add new sensor view should remain
*/
function selectView() {
var newSensorDiv = document.getElementById("add-new-sensor");
var existingSensorDiv = document.getElementById("existing-sensors");
var modifyButton = document.getElementById("current-sensor-btn");
var newButton = document.getElementById("add-sensor-btn");

var newSensorDiv = document.getElementById("add-new-sensor");
var existingSensorDiv = document.getElementById("existing-sensors");
var newTypeDiv = document.getElementById("add-new-type");
var viewTypesDiv = document.getElementById("view-existing-types");
var editSensorsDiv = document.getElementById("edit-sensors");
var editSensorTypesDiv = document.getElementById("edit-sensor-types");

var modifyButton = document.getElementById("current-sensor-btn");
var newSensorButton = document.getElementById("add-sensor-btn");
var newTypeButton = document.getElementById("add-sensor-type-btn");
var viewTypesButton = document.getElementById("view-sensor-types-btn");
var editSensorsButton = document.getElementById("edit-sensors-btn");
var editSensorTypesButton = document.getElementById("edit-sensor-types-btn");

if (sessionStorage.getItem('viewing') == 'addingNew'){
newSensorDiv.style.display = "block";
existingSensorDiv.style.display = 'none';
newTypeDiv.style.display = "none";
viewTypesDiv.style.display = "none";
editSensorsDiv.style.display = "none";
editSensorTypesDiv.style.display = "none";

modifyButton.style.backgroundColor = 'var(--light-accent)';
newButton.style.backgroundColor = 'var(--green)';
newSensorButton.style.backgroundColor = 'var(--green)';
newTypeButton.style.backgroundColor = 'var(--light-accent)';
viewTypesButton.style.backgroundColor = 'var(--light-accent)';
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--light-accent)';
}
else {
else if (sessionStorage.getItem('viewing') == 'view-sensors'){
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'block';
newTypeDiv.style.display = "none";
viewTypesDiv.style.display = "none";
editSensorsDiv.style.display = "none";
editSensorTypesDiv.style.display = "none";

modifyButton.style.backgroundColor = 'var(--green)';
newButton.style.backgroundColor = 'var(--light-accent)';
newSensorButton.style.backgroundColor = 'var(--light-accent)';
newTypeButton.style.backgroundColor = 'var(--light-accent)';
viewTypesButton.style.backgroundColor = 'var(--light-accent)';
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--light-accent)';
}
else if (sessionStorage.getItem('viewing') == 'addingNewType'){
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'none';
newTypeDiv.style.display = "block";
viewTypesDiv.style.display = "none";
editSensorsDiv.style.display = "none";
editSensorTypesDiv.style.display = "none";

modifyButton.style.backgroundColor = 'var(--light-accent)';
newSensorButton.style.backgroundColor = 'var(--light-accent)';
newTypeButton.style.backgroundColor = 'var(--green)';
viewTypesButton.style.backgroundColor = 'var(--light-accent)';
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--light-accent)';
}
else if (sessionStorage.getItem('viewing') == 'viewingTypes'){
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'none';
newTypeDiv.style.display = "none";
viewTypesDiv.style.display = "block";
editSensorsDiv.style.display = "none";
editSensorTypesDiv.style.display = "none";

modifyButton.style.backgroundColor = 'var(--light-accent)';
newSensorButton.style.backgroundColor = 'var(--light-accent)';
newTypeButton.style.backgroundColor = 'var(--light-accent)';
viewTypesButton.style.backgroundColor = 'var(--green)';
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--light-accent)';
}
else if (sessionStorage.getItem('viewing') == 'editingSensors'){
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'none';
newTypeDiv.style.display = "none";
viewTypesDiv.style.display = "none";
editSensorsDiv.style.display = "block";
editSensorTypesDiv.style.display = "none";

modifyButton.style.backgroundColor = 'var(--light-accent)';
newSensorButton.style.backgroundColor = 'var(--light-accent)';
newTypeButton.style.backgroundColor = 'var(--light-accent)';
viewTypesButton.style.backgroundColor = 'var(--light-accent)';
editSensorsButton.style.backgroundColor = 'var(--green)';
editSensorTypesButton.style.backgroundColor = 'var(--light-accent)';
}
else if (sessionStorage.getItem('viewing') == 'editingSensorTypes'){
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'none';
newTypeDiv.style.display = "none";
viewTypesDiv.style.display = "none";
editSensorsDiv.style.display = "none";
editSensorTypesDiv.style.display = "block";

modifyButton.style.backgroundColor = 'var(--light-accent)';
newSensorButton.style.backgroundColor = 'var(--light-accent)';
newTypeButton.style.backgroundColor = 'var(--light-accent)';
viewTypesButton.style.backgroundColor = 'var(--light-accent)';
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--green)';
}
}

function displayCurrentSensors() {
sessionStorage.setItem('viewing', 'existing');
selectView()
sessionStorage.setItem('viewing', 'view-sensors');
selectView()
}

function displayAddNewSensor() {
sessionStorage.setItem('viewing', 'addingNew');
selectView()
}

function displayAddNewSensorType() {
sessionStorage.setItem('viewing', 'addingNewType');
selectView()
}

function displaySensorTypes() {
sessionStorage.setItem('viewing', 'viewingTypes');
selectView()
}

function displayEditSensors() {
sessionStorage.setItem('viewing', 'editingSensors');
selectView()
}

function displayEditSensorTypes() {
sessionStorage.setItem('viewing', 'editingSensorTypes');
selectView()
}