def rate_show(request, id): rate = get_object_or_404(Rate, pk=id) rate.view_list = [[_('Disease'), rate.disease], [_('Rate Type'), rate.get_rate_type_display()], [_('Sex'), rate.get_sex_display()], [_('Region'), rate.region], [_('Country'), rate.country], [_('Age Range'), '%d-%d' % (rate.age_start, rate.age_end)], [_('Epoch'), '%d-%d' % (rate.epoch_start, rate.epoch_end)], [_('Rate'), '%d/%d = %0.5f' % (rate.numerator, rate.denominator, rate.rate)], ] return render_to_response('rate/show.html', view_utils.template_params(rate))
def disease_model_show(request, id, format='html'): dm = get_object_or_404(DiseaseModel, id=id) if format == 'html': return render_to_response('disease_model/show.html', view_utils.template_params(dm, id_str=dm.get_asrf_id_str(), asrfs=dm.rates.all())) # TODO: handle json & csv formats if format in ['json', 'csv']: if format == 'json': data_str = json.dumps([[rf.id, rf.fit] for rf in dm.rates.all()]) elif format == 'csv': headings = {} rows = {} data_str = '' for rf in dm.rates.all(): headings[rf] = ['Age (years)', 'MAP Rate (per 1.0)'] rows[rf] = [[a, p] for a,p in zip(rf.fit['out_age_mesh'], rf.fit['map'])] data_str += view_utils.csv_str(headings[rf], rows[rf]) return HttpResponse(data_str, view_utils.MIMETYPE[format]) else: raise Http404
def population_show(request, id): pop = get_object_or_404(Population, pk=id) return render_to_response('population/show.html', view_utils.template_params(pop))
def age_specific_rate_function_show(request, id_str, format='html'): asrfs = view_utils.id_str_to_objects(id_str, AgeSpecificRateFunction) if format == 'html': return render_to_response('age_specific_rate_function/show.html', view_utils.template_params(asrfs[0], asrfs=asrfs, id_str=id_str, query_str=request.META['QUERY_STRING'])) # handle json & csv formats if format in ['json', 'csv']: if format == 'json': data_str = json.dumps([[rf.id, rf.fit] for rf in asrfs]) elif format == 'csv': headings = {} rows = {} data_str = '' for rf in asrfs: headings[rf] = ['Age (years)', 'MAP Rate (per 1.0)'] rows[rf] = [[a, p] for a,p in zip(rf.fit['out_age_mesh'], rf.fit['map'])] data_str += view_utils.csv_str(headings[rf], rows[rf]) return HttpResponse(data_str, view_utils.MIMETYPE[format]) # handle graphics formats cnt = asrfs.count() cols = 2 rows = int(np.ceil(float(cnt) / float(cols))) subplot_width = 6 subplot_height = 4 view_utils.clear_plot(width=subplot_width*cols,height=subplot_height*rows) for ii, rf in enumerate(asrfs): pl.subplot(rows,cols,ii+1) if request.GET.get('bars'): bars_mcmc_fit(rf) #plot_map_fit(rf, alpha=.3) plot_truth(rf) else: plot_intervals(rf, rf.rates.all(), fontsize=12, alpha=.5) plot_intervals(rf, rf.rates.filter(params_json__contains='Rural'), fontsize=12, alpha=.5, color='brown') #plot_normal_approx(rf) plot_map_fit(rf) plot_mcmc_fit(rf) plot_truth(rf) plot_prior(rf) pl.text(0,0,rf.fit.get('priors',''), color='black', family='monospace', alpha=.75) view_utils.label_plot('%s (id=%d)' % (rf, rf.id), fontsize=10) max_rate = np.max([.0001] + [r.rate for r in rf.rates.all()] + rf.fit.get('mcmc_upper_cl', [])) xmin = float(request.GET.get('xmin', default=0.)) xmax = float(request.GET.get('xmax', default=100.)) ymin = float(request.GET.get('ymin', default=0.)) ymax = float(request.GET.get('ymax', default=1.25*max_rate)) pl.axis([xmin, xmax, ymin, ymax]) if ii % cols != 0: pl.ylabel('') #pl.yticks([]) if (ii + cols) < cnt: pl.xlabel('') #pl.xticks([]) return HttpResponse(view_utils.figure_data(format), view_utils.MIMETYPE[format])