示例#1
0
    def getHTML(self, request, user, model):
        from django.template import loader
        cf = CursorsForm(cursors_num=1)
        template = loader.get_template('manager/form.html')
        context = {'form': cf, 'submit': 'forward'}
        cf_txt = template.render(context=context, request=request)
        p = pm.PlotManager()
        for cd in model.dataset.curves_data.all():
            ylen = len(cd.yVector)
            newy = np.absolute(np.fft.fft(cd.yVector))
            newy = newy[:round(ylen / 2.0)].tolist()
            p.add(y=newy,
                  x=range(math.ceil(ylen / 2)),
                  plottype='line',
                  color='red')

        p.setInteraction('set1cursor')
        p.include_x_switch = False
        p.plot_height = 300
        p.plot_width = 500
        src, divPlot, divBut = p.getEmbeded(request, user, 'processing',
                                            model.id)
        return {
            'head':
            src,
            'body':
            ' '.join([
                '<div style="height: 300px;">', divPlot,
                '</div><div style="height: 60px;">', divBut, '</div><div>',
                cf_txt, '</div>'
            ])
        }
示例#2
0
    def getInfo(self, request, user):
        p = pm.PlotManager()
        p.plot_width = 500
        p.plot_height = 400
        xvec = self.model.customData['matrix'][0]
        yvec = self.model.customData['matrix'][1]
        for sens, yrow in yvec:
            p.add(x=xvec, y=yrow, plottype='scatter', color='red', size=7)
        xvec2 = list(xvec)
        xvec2.append(-self.model.customData['result'])
        for k, fe in self.model.customData['fitEquation'].items():
            Y = [fe['slope'] * x + fe['intercept'] for x in xvec2]
            p.add(x=xvec2, y=Y, plottype='line', color='blue', line_width=2)

        scripts, div = p.getEmbeded(request, user, 'analysis', self.model.id)
        ret = {
            'head':
            ''.join([p.required_scripts, scripts]),
            'body':
            ''.join([
                div, '<p>Result: {0}<br />STD: {1}</p>'.format(
                    self.model.customData['result'],
                    self.model.customData['resultStdDev'])
            ])
        }
        return ret
示例#3
0
    def getFinalContent(self, request, user):
        p = pm.PlotManager()
        p.plot_width = 500
        p.plot_height = 400
        p.sizing_mode = 'fixed'
        p.xlabel = 'c_({analyte}) / {units}'.format(
            analyte=self.model.custom_data['analyte'],
            units=self.model.custom_data['units'])
        p.ylabel = 'i / µA'
        xvec = self.model.custom_data['matrix'][0]
        yvec = self.model.custom_data['matrix'][1]
        colors = [
            'blue', 'red', 'green', 'gray', 'cyan', 'yellow', 'magenta',
            'orange'
        ]

        def getColor(x):
            return colors[x] if len(colors) > x else 'black'

        col_cnt = 0
        for sens, yrow in yvec:
            p.add(x=xvec,
                  y=yrow,
                  plottype='scatter',
                  color=getColor(col_cnt),
                  size=7)
            col_cnt += 1
        xvec2 = list(xvec)
        xvec2.append(-self.model.custom_data['result'])
        col_cnt = 0
        for k, fe in self.model.custom_data['fitEquation'].items():
            Y = [fe['slope'] * x + fe['intercept'] for x in xvec2]
            p.add(x=xvec2,
                  y=Y,
                  plottype='line',
                  color=getColor(col_cnt),
                  line_width=2)
            col_cnt += 1

        scripts, div, buttons = p.getEmbeded(request, user, 'analysis',
                                             self.model.id)
        unitsTrans = dict(mmodels.Dataset.CONC_UNITS)
        sig_dig = significant_digit(self.model.custom_data['resultStdDev'], 2)
        ret = {
            'head':
            scripts,
            'body':
            ''.join([
                '<table><tr><td style="width: 500px; height: 400px">', div,
                '</td></tr><tr><td>',
                '<p>Analyte: {0}<br />Result (x&#772; &pm; std): {1} &pm; {2} {3}</p>'
                .format(
                    self.model.custom_data['analyte'],
                    '%.*f' % (sig_dig, self.model.custom_data['result']),
                    '%.*f' % (sig_dig, self.model.custom_data['resultStdDev']),
                    self.model.custom_data['units']), '</td></tr></table>'
            ])
        }
        return ret
示例#4
0
 def getFinalContent(self, request, user):
     p = pm.PlotManager()
     data = p.analysisHelper(self.model.owner, self.model.id)
     for d in data:
         p.add(**d)
     p.plot_width = 500
     p.plot_height = 400
     p.sizing_mode = 'fixed'
     p.xlabel = 'c_({analyte}) / {units}'.format(
         analyte=self.model.custom_data['analyte'],
         units=self.model.custom_data['units'])
     p.ylabel = 'i / µA'
     scr, div, buttons = p.getEmbeded(request, user, 'analysis',
                                      self.model.id)
     n = len(self.model.custom_data['matrix'][0])
     talpha = t.ppf(0.975, n - 2)
     conf_interval = np.multiply(self.model.custom_data['resultStdDev'],
                                 talpha)
     sd = significant_digit(conf_interval, 2)
     slope_interval = np.multiply(self.model.custom_data['slopeStdDev'],
                                  talpha)
     slopesd = significant_digit(slope_interval, 2)
     int_interval = np.multiply(self.model.custom_data['interceptStdDev'],
                                talpha)
     intsd = significant_digit(int_interval, 2)
     return {
         'head':
         scr,
         'body':
         ''.join([
             '<table><tr><td style="width: 500px; height: 400px">', div, """
             </td></tr><tr><td>
                 Analyte: {an}<br />
                 Equation: y = {slope}(&plusmn;{sci}) &middot; x + {int}(&plusmn;{ici})<br />
                 r = {corrcoef}<br />
                 Result: {res}&plusmn;{ci} {anu}
                 </td></tr></table>
             """.format(
                 res='%.*f' % (sd, self.model.custom_data['result']),
                 ci='%.*f' % (sd, conf_interval),
                 corrcoef='%.4f' % self.model.custom_data['corrCoef'],
                 slope='%.*f' %
                 (slopesd, self.model.custom_data['fitEquation']['slope']),
                 sci='%.*f' % (slopesd, slope_interval),
                 int='%.*f' %
                 (intsd,
                  self.model.custom_data['fitEquation']['intercept']),
                 ici='%.*f' % (intsd, int_interval),
                 an=self.model.custom_data['analyte'],
                 anu=self.model.custom_data['units'])
         ])
     }
示例#5
0
    def getHTML(self, user, request, model):
        p = pm.PlotManager()
        for cd in model.curveSet.usedCurveData.all():
            ylen = len(cd.yVector)
            newy = np.absolute(np.fft.fft(cd.yVector))
            newy = newy[1:round(ylen / 2.0)].tolist()
            p.add(y=newy,
                  x=range(round(ylen / 2)),
                  plottype='line',
                  color='red')

        p.setInteraction('set1cursor')
        p.include_x_switch = True
        src, div = p.getEmbeded(request, user, 'processing', model.id)
        return {'head': src, 'body': div}
示例#6
0
def plotInteraction(request, user):
    if request.method != 'POST' or not request.POST.get('query', None):
        return HttpResponse('Error')

    ret = ''
    if (request.POST.get('query') == 'methodmanager'):
        vtype = request.POST.get('vtype', '')
        vid = int(request.POST.get('vid', -1))
        kwrg = {vtype: vid}
        mm = mmm.MethodManager(user=user, **kwrg)
        mm.process(request=request, user=user)
        ret = mm.getJSON(user=user)
    elif (request.POST.get('query') == 'plotmanager'):
        import manager.plotmanager as mpm
        pm = mpm.PlotManager()
        ret = pm.plotInteraction(request=request, user=user)
    else:
        raise NameError('Unknown query type')

    return JsonResponse(ret)
示例#7
0
 def getInfo(self, request, user):
     p = pm.PlotManager()
     data = p.analysisHelper(self.model.owner, self.model.id)
     for d in data:
         p.add(**d)
     p.plot_width = 500
     p.plot_height = 500
     scr, div = p.getEmbeded(request, user, 'analysis', self.model.id)
     return {
         'head':
         ''.join([p.required_scripts, scr]),
         'body':
         ''.join([
             div, 'Equation: y={2}*x+{3}<br />Result: {0}, STD: {1}'.format(
                 self.model.customData['result'],
                 self.model.customData['resultStdDev'],
                 self.model.customData['fitEquation']['slope'],
                 self.model.customData['fitEquation']['intercept'])
         ])
     }
示例#8
0
def generate_plot(request, user, plot_type, value_id, **kwargs):
    allowedTypes = ['file', 'analysis', 'curveset', 'curves']
    if not (plot_type in allowedTypes):
        return
    vtype = kwargs.get('vtype', plot_type)
    vid = kwargs.get('vid', value_id)
    addTo = kwargs.get('add', None)

    pm = mpm.PlotManager()
    data = []
    if (plot_type == 'file'):
        data = pm.fileHelper(user, value_id)
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True
    elif (plot_type == 'curveset'):
        data = pm.curveSetHelper(user, value_id)
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True
    elif (plot_type == 'analysis'):
        data = pm.analysisHelper(user, value_id)
        xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = False
    elif (plot_type == 'curves'):
        data = pm.curvesHelper(user, value_id)
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True

    pm.ylabel = 'i / µA'
    pm.setInteraction(kwargs.get('interactionName', 'none'))

    for d in data:
        pm.add(**d)

    if addTo:
        for a in addTo:
            pm.add(**a)

    return pm.getEmbeded(request, user, vtype, vid)
示例#9
0
def generate_plot(request: HttpRequest,
                  user: User,
                  to_plot: Optional[str] = None,
                  plot_type: Optional[str] = None,
                  value_id: Optional[int] = None,
                  **kwargs) -> List:
    assert (to_plot is not None
            and plot_type is None) or (to_plot is None
                                       and plot_type is not None)
    if to_plot is not None:
        if isinstance(to_plot, mmodels.File):
            plot_type = 'file'
        elif isinstance(to_plot, mmodels.Dataset):
            plot_type = 'dataset'
        elif isinstance(to_plot, mmodels.Fileset):
            plot_type = 'fileset'
        elif isinstance(to_plot, mmodels.Analysis):
            plot_type = 'analysis'
        else:
            raise VoltPyFailed('Could not plot')

    allowedTypes = [
        'file',
        'analysis',
        'dataset',
        'fileset',
    ]
    if plot_type not in allowedTypes:
        raise VoltPyNotAllowed('Operation not allowed.')
    vtype = kwargs.get('vtype', plot_type)
    vid = kwargs.get('vid', value_id)
    addTo = kwargs.get('add', None)

    pm = mpm.PlotManager()
    data = []
    if plot_type == 'file':
        if to_plot is None:
            cf = mmodels.File.get(id=value_id)
        else:
            cf = to_plot
        data = pm.datasetHelper(user, cf)
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True
    elif plot_type == 'dataset':
        if to_plot is None:
            cs = mmodels.Dataset.get(id=value_id)
        else:
            cs = to_plot
        data = pm.datasetHelper(user, cs)
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True
    elif plot_type == 'analysis':
        if to_plot is None:
            data = pm.analysisHelper(user, value_id)
        else:
            data = to_plot
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = False
    elif plot_type == 'fileset':
        if to_plot is None:
            fs = mmodels.Fileset.get(id=value_id)
        else:
            fs = to_plot
        data = []
        for f in fs.files.all():
            data.extend(pm.datasetHelper(user, f))
        pm.xlabel = pm.xLabelHelper(user)
        pm.include_x_switch = True

    pm.ylabel = 'i / µA'
    pm.setInteraction(kwargs.get('interactionName', 'none'))

    for d in data:
        pm.add(**d)

    if addTo:
        for a in addTo:
            pm.add(**a)

    return pm.getEmbeded(request, user, vtype, vid)