Get the App
SLTechnology News&Howtos  ›  Servers  › 

Python statistics of concurrency in time

Shulou Source: shulou.com Published: 2022-06-02 09:24:36 09月22日 Update

# coding:utf-8# 1. Import module # datatime module is used to define time and time addition and subtraction # MySQLdb module is used for Python2.0 connection database, Python3.0 connection database module uses pymysql# xlwt module is excel operation module, which is used to write data to import datetimeimport MySQLdbimport xlwt# 2 in excel. Connect to the database, get the data # MySQLdb.connect defines the properties of the connection database # myconn.cursor () defines the cursor object # query_sql defines the query statement # mycursor.execute () executes the query statement, only executes the statement, and does not output the result. # mycursor.fetchall () extracts query data. All all data, one single data, how many pieces of data are fetched by many. Fetchmany (10) fetches 10 pieces of data. # mycursor.close () close cursor # myconn.close () close connection myconn = MySQLdb.connect (host='1',user='wn',passwd='9eu',db='bs',charset='utf8') mycursor = myconn.cursor () query_sql = 'select JOIN_TIME LEAVE_TIME from commfee where JOIN_TIME between '2019-12-24 15 mycursor.execute' (query_sql) sql_result = mycursor.fetchall () mycursor.close () myconn.close () # 3. Define the global parameter # sum1 = [] define the list sum1,sum1 time list used to generate comparisons # sum2 = [] define the list sum2,sum2 uses to generate concurrent numbers sum1 = [] sum2 = [] # 4. Define the data filter function # compare_time comparison time, with the first value of the start time. # start_time = [sql_ result [I] [0] for i in range (0Len (sql_result))] splits the query result into two lists, start_time and end_time. # compare_time < start_ timeLen (sql_result)-1], compare the compare_time time with the time in the start_time list # compare_time + = datetime.timedelta (seconds=1). After each comparison, the compare_time time + time datetime.timedelta (seconds=1), timedelta (seconds=1) time change 1s# sum1.append (compare_time), and the resulting compare_time is written to the sum1 list. Def query_data (): compare_time = sql_result [0] [0] start_time = [sql_ result [I] [0] for i in range (0 sql_ Len (sql_result))] end_time = [sql_ result [I] [1] for i in range (0) Len (sql_result))] while compare_time < start_ timeLen (sql_result)-1]: compare_time + = datetime.timedelta (seconds=1) count1 = 0 count2 = 0 for time1 in start_time: if time1

Tags: Data time module database format query statement function unit cursor result generation two global parameter object attribute code table change Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Redmi MySQL OPPO Reno