Example #1
0
 def Quary_one(self,city,startdate):
     dc = oper_database.ConnectDB()
     if dc.Error_flag == 0:
         onedata = dc.QuaryWeaData(city, startdate)
         dc.closeDB()
         if onedata == -1:
             return 0
             # 数据库无此数据
         else:
             list=[]
             for index, item in enumerate(onedata):
                 dlist=[]
                 dlist.append(item[1][11:])
                 dlist.append(item[5])
                 dlist.append(str(item[2]))
                 dlist.append(item[3])
                 if item[4] == '-1' or item[4] == '0':
                     dlist.append('暂无数据')
                 else:
                     dlist.append(item[4])
                 dlist.append(item[6])
                 dlist.append(item[7])
                 list.append(dlist)
             return list
     else:
         return -1
Example #2
0
    def Year_contrast(self, city):
        today = datetime.datetime.now().strftime('%Y-%m-%d')
        dc = oper_database.ConnectDB()
        if dc.Error_flag == 0:

            datam1 = dc.QuaryWeaDataSE(city, '2019-01-01', '2019-12-31')
            datam2 = dc.QuaryWeaDataSE(city, '2020-01-01', '2020-12-31')
            datam3 = dc.QuaryWeaDataSE(city, '2021-01-01', today)

            list1 = []
            list2 = []
            list3 = []

            for index, value in datam1.items():
                dict = {}
                dict['date'] = index
                dict['max'] = value[0]
                dict['min'] = value[1]
                list1.append(dict)

            for index, value in datam2.items():
                dict = {}
                dict['date'] = index
                dict['max'] = value[0]
                dict['min'] = value[1]
                list2.append(dict)

            for index, value in datam3.items():
                dict = {}
                dict['date'] = index
                dict['max'] = value[0]
                dict['min'] = value[1]
                list3.append(dict)

            list = []
            list.append(list1)
            list.append(list2)
            list.append(list3)

            dc.closeDB()

            # not none
            if list != []:
                return list
            else:
                return 0
                # 数据库无此数据
        else:
            return -1  # 数据库连接异常
Example #3
0
    def AverageTemp_Month(self, city):
        dc = oper_database.ConnectDB()
        if dc.Error_flag == 0:
            yearlist = [2019, 2020, 2021]
            monthlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
            today = datetime.datetime.now().strftime('%Y-%m-%d')
            datelist = []
            for y in yearlist:
                datelist_y = []
                for m in monthlist:
                    d = '-30'
                    #闰年
                    if ((y % 4 == 0 and y % 100 != 0) or
                        (y % 400 == 0)) and m == 2:
                        d = '-29'
                    elif m == 2:
                        d = '-28'
                    if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12:
                        d = '-31'
                    datelist_m = dc.getDatesByTimes(
                        str(y) + '-' + str(m) + '-01',
                        str(y) + '-' + str(m) + d)
                    datelist_y.append(datelist_m)
                datelist.append(datelist_y)
            avetemp_y = []

            for y in datelist:  #每年
                avetemp_m = []
                for m in y:  #每月
                    datam = dc.QuaryWeaDataSETemp(city, m[0], m[-1])
                    if datam != -1:
                        average_a = np.mean(datam)
                    else:
                        average_a = 0
                    avetemp = round(average_a, 2)
                    avetemp_m.append(avetemp)
                avetemp_y.append(avetemp_m)
            dc.closeDB()
            if avetemp_y != []:
                return avetemp_y
            else:
                return 0
        else:
            return -1  # 数据库连接异常


# da = Data_Analyse()
# da.AverageTemp_Month('311')
Example #4
0
 def Login(self, id, pwd):
     if id == '' or pwd == '':
         return 0  # 帐号或密码不能为空
     dc = oper_database.ConnectDB()
     if dc.Error_flag == 0:
         f = dc.login(id, pwd)
         if f == 1:
             return 1
         elif f == -1:
             return -1
             # 密码错误
         else:
             return 2
             #账户不存在
     else:
         return -2
Example #5
0
 def Quary_many(self,city, startdate, enddate):
     dc = oper_database.ConnectDB()
     if dc.Error_flag == 0:
         datelist = dc.getDatesByTimes(startdate, enddate)
         list = []
         for time in datelist:
             data = dc.QuaryWeaData(city, time)
             dict = {}
             if data != -1: # not none
                 temp = [t[2] for t in data]
                 temp.sort(reverse=True)
                 max = temp[0]
                 min = temp[len(temp) - 1]
                 wea = [w[5] for w in data]
                 wea = np.array(wea)
                 key = np.unique(wea)
                 result = {}
                 for k in key:#统计一天中各个天气类型的数量
                     mask = (wea == k)
                     list_new = wea[mask]
                     v = list_new.size
                     result[k] = v
                 d_order = sorted(result.items(), key=lambda x: x[1], reverse=True)#排序
                 wea_1 = d_order[0][0]#一天中发生最多的天气状况
                 # 通过以下方法,确定一天的天气是什么:通过雨雪的权重大于雾霾大于晴阴多云实现
                 if len(d_order) > 1 and (d_order[0][0].find('晴') != -1 or d_order[0][0].find('多云') != -1 or d_order[0][0].find('阴') != -1):
                     if (d_order[1][0].find('雨') != -1 or d_order[1][0].find('雪') != -1) and d_order[1][1] > 3:
                         wea_1 = d_order[1][0]
                     elif (d_order[1][0].find('霾') != -1 or d_order[1][0].find('雾') != -1) and d_order[1][1] > 5:
                         wea_1 = d_order[1][0]
                 dict['date'] = str(time)
                 dict['weather'] = wea_1
                 dict['max'] = str(max)
                 dict['min'] = str(min)
                 list.append(dict)
         dc.closeDB()
         if list != []:# not none
             return list
         else:
             return 0# 数据库无此数据
     else:
         return -1 # 数据库连接异常
Example #6
0
    def GetData(self):
        print("开始获取数据集")
        today = datetime.datetime.now().strftime('%Y-%m-%d')
        dc = oper_database.ConnectDB()
        if dc.Error_flag == 0:
            self.list = []
            # datelist = dc.getDatesByTimes('2019-01-01', today)
            data = dc.QuaryWeaDataSE(self.city, '2019-01-01', today)
            if data != -1:
                for index, value in data.items():
                    list_one = []

                    list_one.append(value[0])
                    list_one.append(value[1])
                    list_one.append(value[2])
                    # print(list_one)
                    self.list.append(list_one)

            dc.closeDB()
        else:
            return -1
Example #7
0
 def Quary_many(self, city, flag):
     timelist = [30, 60]
     today = datetime.datetime.now().strftime('%Y-%m-%d')
     dc = oper_database.ConnectDB()
     if dc.Error_flag == 0:
         datelist = dc.date_add(today, timelist[flag - 1])
         start = datelist[0]
         datam = dc.QuaryWeaDataSE(city, start, today)
         list = []
         for index, value in datam.items():
             dict = {}
             dict['date'] = index
             dict['max'] = value[0]
             dict['min'] = value[1]
             list.append(dict)
         dc.closeDB()
         # not none
         if list != []:
             return list
         else:
             return 0  # 数据库无此数据
     else:
         return -1  # 数据库连接异常
Example #8
0
    def Weather_type_days(self, city, flag):
        timelist = [30, 60]
        today = datetime.datetime.now().strftime('%Y-%m-%d')
        today_last1 = today[:3] + '0' + today[4:]
        today_last2 = today[:2] + '19' + today[4:]
        dc = oper_database.ConnectDB()
        if dc.Error_flag == 0:
            datelist1 = dc.date_add(today, timelist[flag - 1])
            datelist2 = dc.date_add(today_last1, timelist[flag - 1])
            datelist3 = dc.date_add(today_last2, timelist[flag - 1])
            weatype = dc.wealist
            weatype = np.array(weatype)
            key = np.unique(weatype)
            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, datelist1[0], today)
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order1 = result
            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, datelist2[0], today_last1)
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order2 = result

            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, datelist3[0], today_last2)
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order3 = result
            resultlist = []
            resultlist.append(d_order1)
            resultlist.append(d_order2)
            resultlist.append(d_order3)
            dc.closeDB()
            # not none
            if resultlist != []:
                return resultlist
            else:
                return 0
        else:
            return -1  # 数据库连接异常
Example #9
0
    def Weather_type_year(self, city):
        today = datetime.datetime.now().strftime('%Y-%m-%d')
        dc = oper_database.ConnectDB()
        if dc.Error_flag == 0:
            datelist3 = dc.getDatesByTimes('2019-01-01', '2019-12-31')
            datelist2 = dc.getDatesByTimes('2020-01-01', '2020-12-31')
            datelist1 = dc.getDatesByTimes('2021-01-01', today)

            weatype = dc.wealist
            weatype = np.array(weatype)
            key = np.unique(weatype)

            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, '2021-01-01', today)
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order1 = result

            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, '2020-01-01', '2020-12-31')
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order2 = result

            result = {}
            for k in key:
                result[k] = 0
            data1 = dc.QuaryWeaDataSEType(city, '2019-01-01', '2019-12-31')
            if data1 != -1:
                wea = np.array(data1)
                for k in key:
                    mask = (wea == k)
                    list_new = wea[mask]
                    v = list_new.size
                    result[k] += v
            d_order3 = result

            resultlist = []
            resultlist.append(d_order1)
            resultlist.append(d_order2)
            resultlist.append(d_order3)
            dc.closeDB()
            # not none
            if resultlist != []:
                return resultlist
            else:
                return 0
                # 数据库无此数据
        else:
            return -1  # 数据库连接异常