Exemplo n.º 1
0
def data_list(request, limit=100, date_time=d):

    # 日付をstr12桁に合わせる --> 2014-11-20 19:40
    date_time = datetime_to_12digits(date_time)

    # データベースから取り出し
    # t = test.objects().limit(10000)
    # t = test.objects(node_id=1244).limit(25000)
    t = test.objects(get_time_no__gte=20150603114000).limit(1000)

    # for i in len(t):
    #   t[i]["get_time_no"] = str(t[i]["get_time_no"])[8:14]

    return render_to_response(
        "pfv/data_list.html",  # 使用するテンプレート
        {
            "t": t,
            "limit": limit,
            "year": date_time[0:4],
            "month": date_time[5:7],
            "day": date_time[8:10],
            "hour": date_time[11:13],
            "minute": date_time[14:16],
        },
    )
Exemplo n.º 2
0
def data_list(request, limit=100, date_time=d):
 
  # 日付をstr12桁に合わせる --> 2014-11-20 19:40
  date_time = datetime_to_12digits(date_time)

  # データベースから取り出し
  t = Sensor2.objects(datetime__gte="2015-06-29 12:40",device_id=66).order_by("-datetime").limit(5500)

  return render_to_response('cms/data_list.html',  # 使用するテンプレート
                              {'t': t, 'limit':limit, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]} )
Exemplo n.º 3
0
def sensor_graph_json(request, limit, date_time, type="101"):
  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)
  date_time = dt_from_str_to_iso(date_time)

  lt = date_time - datetime.timedelta(days = 3)
  gt = date_time - datetime.timedelta(days = int(limit))

  num = 100 # 最大取り出し件数
  t = []

  # データベースから取り出し
  if type[0:1] == "0":
    t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("ac","datetime")
    for i in range(0,num - 1):
      if len(t) > i :
        lt = t[i][1]
        t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("ac","datetime")
  elif type[0:1] == "1":
    t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("ilu","datetime")
    for i in range(0,num - 1):
      if len(t) > i :
        lt = t[i][1]
        t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("ilu","datetime")
  else:
    t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("tu","datetime")
    for i in range(0,num - 1):
      if len(t) > i :
        lt = t[i][1]
        t += Sensor2.objects(device_id=type[1:3],datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").skip(int(limit)*2).limit(1).scalar("tu","datetime")

  # Python辞書オブジェクトとしてdataに格納
  data = []
  if type[0:1] == "0":
    for i in range(0,len(t)):
      data.append({
        'ac':t[i][0],
        'datetime':dt_from_iso_to_jap2(t[i][1]),
        })
  elif type[0:1] == "1":
    for i in range(0,len(t)):
      data.append({
        'ilu':t[i][0],
        'datetime':dt_from_iso_to_jap2(t[i][1]),
        })
  else:
    for i in range(0,len(t)):
      data.append({
        'tu':t[i][0],
        'datetime':dt_from_iso_to_jap2(t[i][1]),
        })
  
  return render_json_response(request, data) # dataをJSONとして出力
Exemplo n.º 4
0
def position_edit(request, date_time):
  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)
  date_time = dt_from_str_to_iso(date_time)

  lt = date_time + datetime.timedelta(minutes = 1)
  gt = date_time - datetime.timedelta(seconds = 1)

  # データベースから取り出し
  t = []
  for s in range(1,number_of_device+1):
    t += positionset.objects(device_id=s, datetime__gt=gt, datetime__lt=lt).order_by("-datetime").limit(1)
  return render_to_response('cms/position_edit.html',  # 使用するテンプレート
                              {'t':t} )      # テンプレートに渡すデータ)
Exemplo n.º 5
0
def sensor_map(request, date_time=999, type="20"):

    # 最近の取得時間の取り出し
    recent = []
    num = 20  # 最大取り出し件数
    today = datetime.datetime.today()
    # recent += Sensor2.objects(datetime__lt=today, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")
    # for i in range(0,num - 1):
    #   if len(recent) > i :
    #     lt = recent[i] - datetime.timedelta(hours = recent[i].hour) - datetime.timedelta(minutes = recent[i].minute + 5)
    #     recent += Sensor2.objects(datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

    # センサーデータの取り出し
    if date_time == 999:
        lt = datetime.datetime.today()
    else:
        lt = dt_from_str_to_iso(datetime_to_12digits(date_time))

    gt = lt - datetime.timedelta(minutes=10)  # 10分前までのデータを取得

    exist_list = []
    mongo_data = []
    # mongo_data += Sensor2.objects(datetime__gt=gt, datetime__lt=lt,error_flag=False).order_by("device_id","-datetime").limit(500)
    # device_list = [False]*99
    # t = []
    # for i in range(0,len(mongo_data)):
    #   if device_list[mongo_data[i]["device_id"]] == False:
    #       device_list[mongo_data[i]["device_id"]] = True
    #       t.append(mongo_data[i])

    # 位置情報の取り出し
    # pos = []
    # for i in range(0,len(t)):
    # pos += positionset.objects(device_id=t[i]["device_id"], datetime__lt=lt).order_by("-datetime").limit(1)

    return render_to_response(
        "pfv/sensor_map.html",  # 使用するテンプレート
        {
            "year": lt.year,
            "month": lt.month,
            "day": lt.day,
            "hour": lt.hour,
            "minute": lt.minute,
            "sensor": type[0:1],
            "visualize": type[1:2],
        },
    )
Exemplo n.º 6
0
def sensor_graph_en(request, limit=100, date_time=d, type="101"):

  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)

  # 直近2日分を取得
  two_days_ago = dt_from_str_to_iso(date_time)
  two_days_ago -= datetime.timedelta(days = 2)
  two_days_ago = dt_from_iso_to_str(two_days_ago)
  two_days_ago = dt_insert_partition_to_min(two_days_ago)

  # データベースから取り出し
  t = Sensor2.objects(device_id=type[1:4],datetime__gt=two_days_ago, datetime__lte=date_time, error_flag=False).order_by("-datetime").limit(int(limit))

  return render_to_response('cms/sensor_graph_en.html',  # 使用するテンプレート
                              {'t': t, 'limit':limit, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]
                              ,'sensor': type[0:1],'device_id':type[1:3]} )
Exemplo n.º 7
0
def data_check(request, date_time=d):

  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)

  # データベースから取り出し
  # t = Sensor2.objects(datetime__lt=date_time).order_by("-datetime").limit(int(limit))

  error_data = Sensor2.objects(datetime__lt=date_time, error_flag=True).order_by("-datetime")

  total = Sensor2.objects(datetime__lt=date_time, error_flag=False).count()
  total_e = Sensor2.objects(datetime__lt=date_time, error_flag=True).count()
  total_ini = initial_db.objects(datetime__lt=date_time).count()
  data = []
  t = []

  for s in device_list:
    d0 = s
    d1 = Sensor2.objects(device_id=s, datetime__lt=date_time, error_flag=False).count()
    d2 = Sensor2.objects(device_id=s, datetime__lt=date_time, error_flag=True).count()
    d3 = initial_db.objects(device_id=s, datetime__lt=date_time).count()
    d4 = Sensor2.objects(device_id=s, datetime__lt=date_time, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

    for i in d4:
      d4 = i
    tmp_list = (d0, d1, d2, d3, d4),
    t += tmp_list

  for i in range(0,len(t)):
    data.append({
      'device_id':t[i][0],
      'data':t[i][1],
      'error':t[i][2],
      'initial':t[i][3],
      'datetime':t[i][4]      
      })

  return render_to_response('cms/data_check.html',  # 使用するテンプレート
                              {'data': data, 'total': total, 'total_e': total_e, 'total_ini': total_ini, 
                              'error_data': error_data,'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]})
Exemplo n.º 8
0
def sensor_map(request, date_time=999, type="20"):

  # 最近の取得時間の取り出し
  recent = []
  num = 20 # 最大取り出し件数
  today = datetime.datetime.today()
  # recent += Sensor2.objects(datetime__lt=today, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")
  # for i in range(0,num - 1):
  #   if len(recent) > i :
  #     lt = recent[i] - datetime.timedelta(hours = recent[i].hour) - datetime.timedelta(minutes = recent[i].minute + 5)
  #     recent += Sensor2.objects(datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

  # センサーデータの取り出し
  if date_time == 999:
    lt = datetime.datetime.today()
  else:
    lt = dt_from_str_to_iso(datetime_to_12digits(date_time))

  gt = lt - datetime.timedelta(minutes = 10) # 10分前までのデータを取得

  exist_list = []
  mongo_data = []
  mongo_data += Sensor2.objects(datetime__gt=gt, datetime__lt=lt,error_flag=False).order_by("device_id","-datetime").limit(500)
  device_list = [False]*99
  t = []
  for i in range(0,len(mongo_data)):
    if device_list[mongo_data[i]["device_id"]] == False:
        device_list[mongo_data[i]["device_id"]] = True
        t.append(mongo_data[i])

  # 位置情報の取り出し
  pos = []
  for i in range(0,len(t)):
    pos += positionset.objects(device_id=t[i]["device_id"], datetime__lt=lt).order_by("-datetime").limit(1)

  return render_to_response('cms/sensor_map.html'
  ,  # 使用するテンプレート
                              {'t': t, 'pos':pos, 'year':lt.year,'month':lt.month
                              ,'day':lt.day,'hour':lt.hour,'minute':lt.minute
                              ,'sensor':type[0:1],'visualize':type[1:2]} 
                              )
Exemplo n.º 9
0
def data_list2(request, limit=100, date_time=d):

  date_time = datetime_to_12digits(date_time)

  lmt = '50' # 親機1台につき取得するデータの件数
  datetime = '"201411101700"' # データ取得時刻
  s = []
  for num in "6789": # 親機ループ 6~9

    r = requests.get('http://api1.ginga-box.com:8080/ginga/sol?mode=getdata&v={box_id:"9CBD9D01000'+num+'", limit:'+lmt+', datetime:'+datetime+'}')
    t = r.json()

    # データの加工
    for i in range(len(t)):
      t[i] = convert_sensor_data(t[i])
    s+=t
    # s = sorted(s.keys("datetime"))
  
  return render_to_response('cms/data_list.html',  # 使用するテンプレート
                              {'t': s, 'limit':limit, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]} )
Exemplo n.º 10
0
def sensor_graph2(request, limit=100, date_time=999, type="ai01"):

  # センサーデータの取り出し
  if date_time == 999:
    lt = datetime.datetime.today()
  else:
    lt = dt_from_str_to_iso(datetime_to_12digits(date_time))

  gt1 = lt - datetime.timedelta(days = 1)
  gt2 = lt - datetime.timedelta(days = 2)
  gt3 = lt - datetime.timedelta(days = 3)

  # データベースから取り出し
  t1 = Sensor2.objects(device_id=type[2:4],datetime__gt=gt1, datetime__lte=lt, error_flag=False).order_by("-datetime")
  t2 = Sensor2.objects(device_id=type[2:4],datetime__gt=gt2, datetime__lte=gt1, error_flag=False).order_by("-datetime")
  t3 = Sensor2.objects(device_id=type[2:4],datetime__gt=gt3, datetime__lte=gt2, error_flag=False).order_by("-datetime")

  return render_to_response('cms/sensor_graph2.html',  # 使用するテンプレート
                              {'t1': t1, 't2': t2, 't3': t3, 'limit':limit, 'year':lt.year,'month':lt.month
                              ,'day':lt.day,'hour':lt.hour,'minute':lt.minute
                              ,'sensor': type[0:2],'device_id':type[2:4]} )
Exemplo n.º 11
0
def position_delete(request, date_time, id=999):
  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)
  date_time = dt_from_str_to_iso(date_time)

  lt = date_time + datetime.timedelta(minutes = 1)
  gt = date_time - datetime.timedelta(seconds = 1)
  count = positionset.objects(datetime__gt=gt, datetime__lt=lt).count()

  if id == 999: # すべてのデバイスの位置情報削除
    positionset.objects(datetime__gt=gt, datetime__lt=lt).delete()
  else: # 特定のデバイスの位置情報のみを削除
    positionset.objects(datetime__gt=gt, datetime__lt=lt, device_id=id).delete()

  # Python辞書オブジェクトとしてdataに格納
  data = []
  data.append({
    'datetime':dt_from_iso_to_jap(date_time),
    'count':count
    })

  return render_json_response(request, data) # dataをJSONとして出力
Exemplo n.º 12
0
def sensor_map_en(request, date_time=999, type="20"):

  # 最近の取得時間の取り出し
  recent = []
  num = 20 # 最大取り出し件数
  today = datetime.datetime.today()
  recent += Sensor2.objects(datetime__lt=today, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")
  for i in range(0,num - 1):
    if len(recent) > i :
      lt = recent[i] - datetime.timedelta(hours = recent[i].hour) - datetime.timedelta(minutes = recent[i].minute + 5)
      recent += Sensor2.objects(datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

  # センサーデータの取り出し
  if date_time == 999:
    lt = datetime.datetime.today()
  else:
    lt = dt_from_str_to_iso(datetime_to_12digits(date_time))

  gt = lt - datetime.timedelta(hours = 1) # 一時間前までのデータを取得

  t = []
  t_ilu = []
  exist_list = []
  for s in device_list:
    t += Sensor2.objects(device_id=s, datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1)
    exist_list += Sensor2.objects(device_id=s, datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("device_id")
  for s in ilu_device_list:
    t_ilu += Sensor2.objects(device_id=s, datetime__gt=gt, datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1)

  # 位置情報の取り出し
  pos = []
  for s in exist_list:
    pos += positionset.objects(device_id=s, datetime__lt=lt).order_by("-datetime").limit(1)

  return render_to_response('cms/sensor_map_en.html',  # 使用するテンプレート
                              {'t': t, 't_ilu': t_ilu,'recent': recent, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]
                              ,'sensor':type[0:1],'visualize':type[1:2]} )
Exemplo n.º 13
0
def sensor_map_en(request, date_time=d, type="20"):

  import datetime

  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)

  onehour_ago = datetime.datetime(int(date_time[0:4]),int(date_time[5:7]),int(date_time[8:10]),int(date_time[11:13]),int(date_time[14:16]))
  onehour_ago -= datetime.timedelta(hours = 1)
  onehour_ago = str(onehour_ago.year)+"-"+("0"+str(onehour_ago.month))[-2:]+"-"+("0"+str(onehour_ago.day))[-2:]+" "+("0"+str(onehour_ago.hour))[-2:]+":"+("0"+str(onehour_ago.minute))[-2:]

  # データベースから取り出し
  t = []
  t_ilu = []

  for s in device_list:
    t += Sensor2.objects(device_id=s, datetime__gt=onehour_ago, datetime__lt=date_time, error_flag=False).order_by("-datetime").limit(1)

  for s in ilu_device_list:
    t_ilu += Sensor2.objects(device_id=s, datetime__gt=onehour_ago, datetime__lt=date_time, error_flag=False).order_by("-datetime").limit(1)

  # 最近の取得時間の取り出し
  recent = []
  num = 5 # 最大取り出し件数
  today = datetime.datetime.today()
  recent += Sensor2.objects(datetime__lt=today, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

  for i in range(0,num - 1):
    if len(recent) > i :
      lt = recent[i] - datetime.timedelta(hours = recent[i].hour) - datetime.timedelta(minutes = recent[i].minute + 5)
      recent += Sensor2.objects(datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")

  return render_to_response('cms/sensor_map_en.html',  # 使用するテンプレート
                              {'t': t, 't_ilu': t_ilu,'recent': recent, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]
                              ,'sensor':type[0:1],'visualize':type[1:2]} )
Exemplo n.º 14
0
def sensor_map(request, date_time=d, type="20"):

  import datetime

  # 文字列を12桁に合わせる
  date_time = datetime_to_12digits(date_time)

  onehour_ago = datetime.datetime(int(date_time[0:4]),int(date_time[5:7]),int(date_time[8:10]),int(date_time[11:13]),int(date_time[14:16]))
  onehour_ago -= datetime.timedelta(hours = 1)
  onehour_ago = str(onehour_ago.year)+"-"+("0"+str(onehour_ago.month))[-2:]+"-"+("0"+str(onehour_ago.day))[-2:]+" "+("0"+str(onehour_ago.hour))[-2:]+":"+("0"+str(onehour_ago.minute))[-2:]

  # db.Sensor2.create_index([("device_id",ASCENDING),("datetime",DESCENDING)])

  # データベースから取り出し
  t = []
  t_ilu = []
  # for s in device_list:
  #   start = datetime.datetime.today()
  #   if db.sensor2.find({"device_id":s, "datetime":{"$gte":onehour_ago, "$lte":date_time}, "error_flag":False}).count() != 0:
  #     t += db.sensor2.find({"device_id":s, "datetime":{"$gte":onehour_ago, "$lte":date_time}, "error_flag":False}).sort("datetime")[1]
  #   # t += Sensor2.objects(device_id=s, datetime__gt=onehour_ago, datetime__lt=date_time, error_flag=False).order_by("-datetime").limit(1)
  #   end = datetime.datetime.today()
  #   print (end - start)

  # for s in ilu_device_list:
  #   start = datetime.datetime.today()
  #   if db.sensor2.find({"device_id":s, "datetime":{"$gte":onehour_ago, "$lte":date_time}, "error_flag":False}).count() != 0:
  #     t_ilu += db.sensor2.find({"device_id":s, "datetime":{"$gte":onehour_ago, "$lte":date_time}, "error_flag":False}).sort("-datetime")[1]
  #   # t += Sensor2.objects(device_id=s, datetime__gt=onehour_ago, datetime__lt=date_time, error_flag=False).order_by("-datetime").limit(1)
  #   end = datetime.datetime.today()
  #   print (end - start)

  # 最近の取得時間の取り出し
  db.Sensor2.create_index([("datetime",DESCENDING)])

  recent = []
  num = 10 # 最大取り出し件数
  today = datetime.datetime.today()

  lt = today - datetime.timedelta(hours = today.hour) - datetime.timedelta(minutes = today.minute + 5)
  gt = today - datetime.timedelta(days = 20)
  # print (lt, gt)

  # tmp_date = dt_from_iso_to_str(today)[:8]
  # dt_datas = list(db.sensor2.find({"datetime":{"$gte":gt, "$lte":lt}, "error_flag":False},{"datetime":1}).sort("datetime", DESCENDING))
  
  # if len(dt_datas) > 0:
  #   for i in range(0, len(dt_datas) - 1):
  #     dt_data = dt_datas[i]

  #     if str(dt_from_iso_to_str(dt_data["datetime"]))[:8] != tmp_date[:8]:
  #       tmp = [dt_data["datetime"]]
  #       recent += tmp

  #     tmp_date = str(dt_from_iso_to_str(dt_data["datetime"]))[:8]
  #     print (tmp_date)

  # else:
  #   recent += [today]

  #   print ("aaaaaaaaaaaaaaa", recent)
  #   pass



  for i in range(0,num - 1):
    # start = datetime.datetime.today()
    if len(recent) > i :
      # lt = recent[i] - datetime.timedelta(hours = recent[i].hour) - datetime.timedelta(minutes = recent[i].minute + 5)
      # gt = recent[i] - datetime.timedelta(days = 30)
      # start = datetime.datetime.today()
      if db.sensor2.find({"datetime":{"$lte":lt, "$gte":gt}, "error_flag":False}).count() != 0:
        # end = datetime.datetime.today()
        # print ("if:", end - start)

        # start = datetime.datetime.today()
        tmp = db.sensor2.find({"datetime":{"$lte":lt, "$gte":gt}, "error_flag":False},{"datetime":1}).sort("-datetime")[1]
        # end = datetime.datetime.today()
        # print ("tmp:", end - start)

        tmp = [tmp["datetime"]]
        # print (type(tmp))
        recent += tmp
      recent += Sensor2.objects(datetime__lt=lt, error_flag=False).order_by("-datetime").limit(1).scalar("datetime")
    # end = datetime.datetime.today()
    # print ("running:",end - start)

  return render_to_response('cms/sensor_map.html',  # 使用するテンプレート
                              {'t': t, 't_ilu': t_ilu,'recent': recent, 'year':date_time[0:4],'month':date_time[5:7]
                              ,'day':date_time[8:10],'hour':date_time[11:13],'minute':date_time[14:16]
                              ,'sensor':type[0:1],'visualize':type[1:2]} )