Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python statistics of concurrency in time

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

# 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report