Skip to content

Commit

Permalink
Started adding graph code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejmets committed Sep 26, 2024
1 parent e93dfdd commit 772083d
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/senaite/timeseries/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/>
<!-- Static Resources Viewlet -->
<browser:viewlet
name="senaite.ast.static"
name="senaite.timeseries.static"
manager="plone.app.layout.viewlets.interfaces.IHtmlHead"
class="senaite.core.browser.viewlets.resources.ResourcesViewlet"
permission="zope2.View"
Expand Down
42 changes: 27 additions & 15 deletions src/senaite/timeseries/browser/results.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.AST.
# This file is part of SENAITE.TIMESERIES.
#
# SENAITE.AST is free software: you can redistribute it and/or modify it under
# SENAITE.TIMESERIES is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, version 2.
#
Expand All @@ -19,21 +19,22 @@
# Some rights reserved, see README and LICENSE.

from bika.lims import api
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from senaite.timeseries.config import is_installed
from senaite.timeseries.config import _
from senaite.timeseries.browser.overrides.analysisrequest import AnalysesView
from senaite.core.browser.viewlets.sampleanalyses import LabAnalysesViewlet


class TimeSeriesAnalysesViewlet(LabAnalysesViewlet):
"""TimeSeries Analyses section viewlet for Sample view
"""
"""TimeSeries Analyses section viewlet for Sample view"""

title = _("Timeseries Results")
icon_name = "client"
capture = "timeseries"

def available(self):
"""Returns true if senaite.ast is installed and the sample contains
"""Returns true if senaite.timeseries is installed and the sample contains
at least one sensitivity testing analysis or the microorganism
identification analysis is present
"""
Expand All @@ -49,15 +50,16 @@ def available(self):


class ManageResultsView(AnalysesView):
"""Listing view for AST results entry
"""
"""Listing view for Time Series results entry"""

contents_table_template = ViewPageTemplateFile("templates/timeseries_results.pt")

def __init__(self, context, request):
super(ManageResultsView, self).__init__(context, request)

self.contentFilter.update({
"getPointOfCapture": "lab",
"getAncestorsUIDs": [api.get_uid(context)]
})
self.contentFilter.update(
{"getPointOfCapture": "lab", "getAncestorsUIDs": [api.get_uid(context)]}
)

self.form_id = "%s_lab_analyses" % api.get_id(context)
self.allow_edit = True
Expand All @@ -67,9 +69,19 @@ def __init__(self, context, request):
self.expand_all_categories = False
self.reorder_analysis_columns()
# Remove the columns we are not interested in from review_states
hide = ["Method", "Instrument", "Analyst", "DetectionLimitOperand",
"Specification", "Uncertainty", "retested", "Attachments",
"DueDate", "Hidden", "Unit"]
hide = [
"Method",
"Instrument",
"Analyst",
"DetectionLimitOperand",
"Specification",
"Uncertainty",
"retested",
"Attachments",
"DueDate",
"Hidden",
"Unit",
]

all_columns = self.columns.keys()
all_columns = filter(lambda c: c not in hide, all_columns)
Expand All @@ -93,7 +105,7 @@ def folderitems(self):


def get_timeseries_analyses(sample, short_title=None, skip_invalid=True):
"""Returns the ast analyses assigned to the sample passed in and for the
"""Returns the timeseries analyses assigned to the sample passed in and for the
microorganism name specified, if any
"""
analyses = sample.getAnalyses(getPointOfCapture="lab")
Expand Down
1 change: 0 additions & 1 deletion src/senaite/timeseries/browser/static/resources.pt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
<script tal:attributes="src string:${view/site_url}//++plone++senaite.ast.static/bundles/senaite.ast.js"></script><link href="#" rel="stylesheet" tal:attributes="href string:${view/site_url}//++plone++senaite.ast.static/bundles/senaite.ast.5e0568240a9f397d2c58.css"/>
83 changes: 0 additions & 83 deletions src/senaite/timeseries/browser/templates/ast_results.pt

This file was deleted.

99 changes: 99 additions & 0 deletions src/senaite/timeseries/browser/templates/timeseries_results.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<tal:contents_table
define="portal context/@@plone_portal_state/portal;"
i18n:domain="senaite.timeseries">

<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<script>
// set the dimensions and margins of the graph
var margin = {top: 10, right: 30, bottom: 30, left: 60},
width = 460 - margin.left - margin.right,
height = 400 - margin.top - margin.bottom;

// append the svg object to the body of the page
var svg = d3.select("#my_dataviz")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");

//Read the data
d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/3_TwoNumOrdered_comma.csv",

// When reading the csv, I must format variables:
function(d){
return { date : d3.timeParse("%Y-%m-%d")(d.date), value : d.value }
},

// Now I can use this dataset:
function(data) {

// Add X axis --> it is a date format
var x = d3.scaleTime()
.domain(d3.extent(data, function(d) { return d.date; }))
.range([ 0, width ]);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x));

// Add Y axis
var y = d3.scaleLinear()
.domain([0, d3.max(data, function(d) { return +d.value; })])
.range([ height, 0 ]);
svg.append("g")
.call(d3.axisLeft(y));

// Add the line
svg.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(function(d) { return x(d.date) })
.y(function(d) { return y(d.value) })
)

debugger;
}
)


</script>

<!-- Results entry listing -->
<form name="listing_form"
class="form form-inline"
method="post"
i18n:domain="senaite.timeseries"
tal:omit-tag="view/omit_form"
tal:attributes="id python:view.form_id;
action python:view.getPOSTAction()">

<input tal:condition="not: view/omit_form"
tal:replace="structure context/@@authenticator/authenticator"/>

<input tal:condition="not: view/omit_form"
type="hidden" name="submitted" value="1"/>

<!-- ReactJS managed component -->
<div class="ajax-contents-table w-100"
tal:attributes="data-form_id python:view.form_id;
data-listing_identifier python:view.listing_identifier;
data-enable_ajax_transitions python:view.ajax_transitions_enabled();
data-pagesize python:view.pagesize;
data-api_url python:view.get_api_url();
data-columns python:view.ajax_columns();
data-show_column_toggles python:view.ajax_show_column_toggles();
data-review_states python:view.ajax_review_states();">
</div>
</form>

<!-- Create a div where the graph will take place -->
<p>WTF</p>
<div id="my_dataviz"></div>
<p>WTF</p>

</tal:contents_table>

0 comments on commit 772083d

Please sign in to comment.