Commit c29d48b6 authored by Pierre-antoine Comby's avatar Pierre-antoine Comby

view landmark

parent a304c0dd
......@@ -5,45 +5,55 @@ from import BaseCommand
from django.conf import settings
from django.apps import apps
from indoor.models import *
from django.db import transaction
# from django.contrib.gis.geos import GEOSGeometry
import os
import csv
import json
import math
from collections import OrderedDict
import pyproj
BDD_DIR = "media/bdd/Base"
class Command(BaseCommand):
help = "Import a csv file to a model"
def add_arguments(self, parser):
parser.add_argument("--map",type=str,help="json mapping header of csv and models")
parser.add_argument("--app",type=str,help="django app name for that model")
def handle(self, *args,**options):
trad = options.get("map",None)
with open(trad,'rb') as f:
map_dict = json.load(f,object_pairs_hook=OrderedDict)
for model in map_dict:
obj_dict = dict()
file_path = map_dict[model][0]
model_dict = map_dict[model][1]
_model = apps.get_model(options["app"],model)
with open(os.path.join(BDD_DIR,file_path),'r', encoding='utf-8-sig') as csv_file:
reader = csv.reader(csv_file,delimiter=";")
reader = csv.reader((line.replace('\0','') for line in csv_file),delimiter=";")
header = next(reader)
for row in reader:
for key,value in zip(header,row):
# on ne conserve que les champs désiré
new_key = model_dict.get(key)
if new_key:
obj_dict[new_key] = value
if obj_dict.get("lat"):
obj_dict["pos"] = "POINT({} {})".format(obj_dict.pop("lat"),
obj_dict["alt"] = obj_dict.pop("alt")
obj, created = _model.objects.get_or_create(**obj_dict)
with transaction.atomic():
for row in reader:
for key,value in zip(header,row):
# on ne conserve que les champs désiré
new_key = model_dict.get(key)
if new_key:
obj_dict[new_key] = value
if obj_dict.get("lat"):
x = float(obj_dict.pop("lat"))
y = float(obj_dict.pop("long"))
coords = pyproj.transform(pyproj.Proj(init="epsg:3857"),
obj_dict["pos"]= 'POINT({:.6f} {:.6f})'.format(coords[0],coords[1])
obj, created = _model.objects.get_or_create(**obj_dict)
if created:
......@@ -71,9 +71,25 @@ class Landmark(models.Model):
floor = models.ForeignKey(Floor,on_delete=models.PROTECT)
filelink = models.ForeignKey(FileMeasure,on_delete=models.PROTECT)
def floor_num(self):
return self.floor.elevation
def popupContent(self):
ret = ""
fingerprints = self.wififingerprint_set.all()
for fp in fingerprints:
ret += "Emetteur:{}</br>".format(fp.emitter.ssid)
ret += "min: {} max: {}</br>".format(fp.min_val,fp.max_val)
ret += "mean: {} ,std: {} </br>".format(fp.average,fp.deviation)
return ret
class Fingerprint(models.Model):
class Meta:
abstract = True
" statistique en un Landmark pour un emetteur donné"
hits = models.IntegerField()
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
......@@ -82,12 +98,14 @@ class Fingerprint(models.Model):
average = models.FloatField()
deviation = models.FloatField()
emitter_type = models.ForeignKey(ContentType,on_delete=models.PROTECT)
emitter_id = models.PositiveIntegerField()
emitter = GenericForeignKey('emitter_type','emitter_id')
landmark = models.ForeignKey(Landmark,on_delete=models.PROTECT)
landmark = models.ForeignKey(Landmark,on_delete=models.CASCADE)
class WifiFingerprint(Fingerprint):
emitter = models.ForeignKey(WifiEmitter,on_delete=models.PROTECT)
class BtFingerprint(Fingerprint):
emitter = models.ForeignKey(BtEmitter,on_delete=models.PROTECT)
class Measure(models.Model):
""" Informations générérique sur une mesure"""
......@@ -110,7 +128,7 @@ class WifiMeasure(Measure):
class BtMeasure(Measure):
frame_content = models.CharField(max_length=255)
frame_content = models.CharField(max_length=1024)
name = models.CharField(max_length=255)
namespace = models.CharField(max_length=255)
instance = models.CharField(max_length=255)
from django.shortcuts import render
from django.views.generic import TemplateView,DetailView
from django.apps import apps
from .models import Landmark
# Create your views here.
class HomePageView(TemplateView):
template_name = 'index.html'
def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
app_models = apps.get_app_config('indoor').get_models()
context["models"] = {model._meta.verbose_name: model.objects.all().count() for model in app_models}
return context
class LandmarkView(TemplateView):
template_name = 'indoor/landmark_detail.html'
def get_context_data(self,**kwargs):
context = super().get_context_data(**kwargs)
context['queryset'] = Landmark.objects.all()
return context
class GeoJsonView(TemplateView):
template_name = 'indoor/geojson.html'
def get_context_data(self,**kwargs):
context = super().get_context_data(*kwargs)
context["qs"] = Landmark.objects.all()
return context
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment