{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "### start to get data TJMCL120502305010 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 244, gps_count is 248, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305012 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 191, gps_count is 192, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305048 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 107, gps_count is 108, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305044 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 156, gps_count is 161, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305026 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 225, gps_count is 227, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305022 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 239, gps_count is 248, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305032 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 162, gps_count is 169, system_count is 0, accum_count is 0 \n", "\n", "### start to get data TJMCL120502305038 from 2021-12-09 10:00:00 to 2021-12-09 11:00:00\n", "# get data from 2021-12-09 10:00:00 to 2021-12-09 11:00:00......... \n", "all data-getting done, bms_count is 6, gps_count is 18, system_count is 0, accum_count is 0 \n", "\n" ] } ], "source": [ "# 获取数据\n", "import sys\n", "from LIB.BACKEND import DBManager\n", "import pymysql\n", "import time, datetime\n", "import dateutil.relativedelta\n", "import pandas as pd\n", "from LIB.BACKEND import DataPreProcess\n", "import V1_0_0.status_sta as status_sta\n", "dataPrePro = DataPreProcess.DataPreProcess()\n", "\n", "\n", "# 更新sn列表\n", "host='rm-bp10j10qy42bzy0q7.mysql.rds.aliyuncs.com'\n", "port=3306\n", "db='qixiang_oss'\n", "user='qx_algo_rw'\n", "password='qx@123456'\n", "conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)\n", "cursor = conn.cursor()\n", "cursor.execute(\"select sn, imei, add_time from app_device where status in (1,2,3)\")\n", "res = cursor.fetchall()\n", "df_sn = pd.DataFrame(res, columns=['sn', 'imei', 'add_time'])\n", "df_sn = df_sn.reset_index(drop=True)\n", "cursor.close()\n", "conn.close()\n", "df_sn['factory'] = '骑享'\n", "\n", "db = 'qx_cas'\n", "conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)\n", "cursor = conn.cursor()\n", "cursor.execute(\"select sn, factory from sn_list\")\n", "res = cursor.fetchall()\n", "df_sn2 = pd.DataFrame(res, columns=['sn', 'factory'])\n", "df_sn2['imei'] = \"\"\n", "df_sn = pd.concat([df_sn, df_sn2], axis=0)\n", "df_sn = df_sn.reset_index(drop=True)\n", "\n", "now_time = datetime.datetime.now()\n", "pre_time = now_time + dateutil.relativedelta.relativedelta(hours=-1)#上个月时间\n", "end_time=datetime.datetime.strftime(now_time,\"%Y-%m-%d %H:00:00\")\n", "start_time=datetime.datetime.strftime(pre_time,\"%Y-%m-%d %H:00:00\")\n", "\n", "dbManager = DBManager.DBManager()\n", "charge_count = 0\n", "drive_count = 0\n", "stand_count = 0\n", "charge_count_jinmao = 0\n", "drive_count_jinmao = 0\n", "stand_count_jinmao = 0\n", "for sn in df_sn['sn'].tolist():\n", " if 'TJMCL'in sn: # 金茂\n", " df_data = dbManager.get_data(sn=sn, start_time=start_time, end_time=end_time, data_groups=['bms', 'gps'])\n", " # \n", " df_bms = df_data['bms']\n", " df_gps = df_data['gps']\n", " factory = '金茂'\n", " charge_count_jinmao, drive_count_jinmao, stand_count_jinmao = status_sta.status_sta(df_bms, df_gps, start_time, charge_count_jinmao, drive_count_jinmao, stand_count_jinmao, factory)\n", "# df_result = pd.DataFrame({'factory':['骑享'], 'time':[start_time], 'charge_count':[charge_count], 'drive_count':[drive_count], 'stand_count':stand_count})\n", "df_result = pd.DataFrame({'factory':['金茂'], 'time':[start_time], 'charge_count':[charge_count_jinmao], 'drive_count':[drive_count_jinmao], 'stand_count':stand_count_jinmao})\n", "\n", "\n", " " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | factory | \n", "time | \n", "charge_count | \n", "drive_count | \n", "stand_count | \n", "
---|---|---|---|---|---|
0 | \n", "金茂 | \n", "2021-12-09 10:00:00 | \n", "0 | \n", "7 | \n", "1 | \n", "