def manage_strata(request, property_uid): ''' Strata management view ''' forestproperty = get_object_for_viewing(request, property_uid) if isinstance(forestproperty, HttpResponse): return forestproperty name = forestproperty.name return render_to_response( 'common/manage_strata.html', {'property_id': property_uid, 'property_name': name}, context_instance=RequestContext(request))
def manage_strata(request, property_uid): ''' Strata management view ''' forestproperty = get_object_for_viewing(request, property_uid) if isinstance(forestproperty, HttpResponse): return forestproperty name = forestproperty.name is_locked = forestproperty.is_locked return render_to_response( 'common/manage_strata.html', {'property_id': property_uid, 'property_name': name, 'property_is_locked': is_locked}, context_instance=RequestContext(request))
def progress(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = {"uid": instance.uid, "complete": p[0], "total": p[1], "html": instance.status_html, "error": 0} if "error" in instance.status_html.lower(): progress["error"] = 1 res = HttpResponse(simplejson.dumps(progress)) res["Content-Type"] = mimetypes.JSON return res return HttpResponse("%s is not an analysis!" % (instance), status=500)
def progress_html(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = { "complete": p[0], "total": p[1], "done": p[1] == p[0], "uid": instance.uid, "name": instance.name, "html": instance.status_html, } return render_to_response("analysis/progress.html", {"progress": progress}) return HttpResponse("%s is not an analysis!" % (instance), status=500)
def get_kml_file(request, uid, session_key='0', input_username=None): load_session(request, session_key) user = request.user if input_username and user.username != input_username: return HttpResponse('Access denied', status=401) instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance full = instance.kml_full response = HttpResponse(full) if is_text(full): response['Content-Type'] = mimetypes.KML else: response['Content-Type'] = mimetypes.KMZ return response
def progress_html(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = { 'complete': p[0], 'total': p[1], 'done': p[1] == p[0], 'uid': instance.uid, 'name': instance.name, 'html': instance.status_html } return render_to_response('analysis/progress.html', {'progress': progress}) return HttpResponse("%s is not an analysis!" % (instance), status=500)
def get_kml_file(request, uid, session_key='0', input_username=None): load_session(request, session_key) user = request.user if input_username and user.username != input_username: return HttpResponse('Access denied', status=401) instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance full = instance.kml_full response = HttpResponse(full) if is_text(full): response['Content-Type'] = mimetypes.KML else: response['Content-Type'] = mimetypes.KMZ return response
def progress_html(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = { 'complete': p[0], 'total': p[1], 'done': p[1] == p[0], 'uid': instance.uid, 'name': instance.name, 'html': instance.status_html } return render_to_response('analysis/progress.html', {'progress': progress}) return HttpResponse("%s is not an analysis!" % (instance), status=500)
def progress(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = { 'complete': p[0], 'total': p[1], 'html': instance.status_html, 'error': 0 } if 'error' in instance.status_html.lower(): progress['error'] = 1 res = HttpResponse(simplejson.dumps(progress)) res['Content-Type'] = mimetypes.JSON return res return HttpResponse("%s is not an analysis!" % (instance), status=500)
def progress(request, uid): instance = get_object_for_viewing(request, uid) if isinstance(instance, HttpResponse): return instance if issubclass(instance.__class__, Analysis): p = instance.progress progress = { 'uid': instance.uid, 'complete': p[0], 'total': p[1], 'html': instance.status_html, 'error': 0 } if 'error' in instance.status_html.lower(): progress['error'] = 1 res = HttpResponse(simplejson.dumps(progress)) res['Content-Type'] = mimetypes.JSON return res return HttpResponse("%s is not an analysis!" % (instance), status=500)
def list_species_sizecls(request, property_uid): ''' Provide a json list of all species and available size classes in the specified variant ''' from django.db import connection forestproperty = get_object_for_viewing(request, property_uid) if isinstance(forestproperty, HttpResponse): return forestproperty variant = forestproperty.variant sql = """ SELECT fia_forest_type_name, --variant_code, MIN(calc_dbh_class) AS min_dbh, MAX(calc_dbh_class) AS max_dbh, COUNT(calc_dbh_class) AS number --avg(calc_dbh_class) as avg_dbh, --count(calc_dbh_class) as count_trees, --stddev(calc_dbh_class) as sdev_dbh FROM treelive_summary summary, trees_conditionvariantlookup cvl WHERE cvl.cond_id = summary.cond_id AND cvl.variant_code = %s GROUP BY fia_forest_type_name, variant_code """ cursor = connection.cursor() cursor.execute(sql, (variant.code,)) res = [] # Suggested diameter classes dbh_classes = [ [0, 2], [2, 6], [6, 12], [12, 24], [24, 36], [36, 48], [48, 999], # the top end will get replaced ] ignore_species = [] for row in cursor.fetchall(): species = row[0] min_dbh = row[1] max_dbh = row[2] count = row[3] relevant_classes = [dict(zip(['min', 'max'], [float(y) for y in x])) for x in dbh_classes if x[1] > min_dbh and x[0] <= max_dbh] # filter if count <= 10: continue if species in ignore_species: continue if 'unknown' in species.lower(): continue if len(relevant_classes) == 0: continue relevant_classes[-1]['max'] = max_dbh # limit top end res.append({ 'species': species, 'size_classes': relevant_classes, }) return HttpResponse(json.dumps(res), mimetype='application/json', status=200)
def list_species_sizecls(request, property_uid): ''' Provide a json list of all species and available size classes in the specified variant ''' from django.db import connection forestproperty = get_object_for_viewing(request, property_uid) if isinstance(forestproperty, HttpResponse): return forestproperty variant = forestproperty.variant sql = """ SELECT fia_forest_type_name, --variant_code, MIN(calc_dbh_class) AS min_dbh, MAX(calc_dbh_class) AS max_dbh, COUNT(calc_dbh_class) AS number --avg(calc_dbh_class) as avg_dbh, --count(calc_dbh_class) as count_trees, --stddev(calc_dbh_class) as sdev_dbh FROM treelive_summary summary, trees_conditionvariantlookup cvl WHERE cvl.cond_id = summary.cond_id AND cvl.variant_code = %s GROUP BY fia_forest_type_name, variant_code """ cursor = connection.cursor() cursor.execute(sql, (variant.code,)) res = [] # Suggested diameter classes dbh_classes = [ [0, 2], [2, 6], [6, 12], [12, 24], [24, 36], [36, 48], [48, 999], # the top end will get replaced ] ignore_species = [] for row in cursor.fetchall(): species = row[0] min_dbh = row[1] max_dbh = row[2] count = row[3] relevant_classes = [dict(zip(['min', 'max'], [float(y) for y in x])) for x in dbh_classes if x[1] > min_dbh and x[0] <= max_dbh] # filter if count <= 10: continue if species in ignore_species: continue if 'unknown' in species.lower(): continue if len(relevant_classes) == 0: continue relevant_classes[-1]['max'] = max_dbh # limit top end res.append({ 'species': species, 'size_classes': relevant_classes, }) return HttpResponse(json.dumps(res), mimetype='application/json', status=200)