CN116132500A - Online time length statistics method and device and computer readable storage medium - Google Patents

Online time length statistics method and device and computer readable storage medium Download PDF

Info

Publication number
CN116132500A
CN116132500A CN202211643054.0A CN202211643054A CN116132500A CN 116132500 A CN116132500 A CN 116132500A CN 202211643054 A CN202211643054 A CN 202211643054A CN 116132500 A CN116132500 A CN 116132500A
Authority
CN
China
Prior art keywords
time
user
client
server
online
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211643054.0A
Other languages
Chinese (zh)
Inventor
陈延喆
姚竞聪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Topsec Technology Co Ltd
Beijing Topsec Network Security Technology Co Ltd
Beijing Topsec Software Co Ltd
Original Assignee
Beijing Topsec Technology Co Ltd
Beijing Topsec Network Security Technology Co Ltd
Beijing Topsec Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Topsec Technology Co Ltd, Beijing Topsec Network Security Technology Co Ltd, Beijing Topsec Software Co Ltd filed Critical Beijing Topsec Technology Co Ltd
Priority to CN202211643054.0A priority Critical patent/CN116132500A/en
Publication of CN116132500A publication Critical patent/CN116132500A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Transfer Between Computers (AREA)

Abstract

The application provides an online time length counting method, an online time length counting device and a computer readable storage medium, and relates to the technical field of online time length of users. The method is applied to a client which is in communication connection with a server, and comprises the following steps: obtaining user login server time, user login client local time, user first call online time interface server time and user first login client local time from a server side; substituting the acquired information into a preset statistical time length model for calculation to acquire the online time length. The method and the device have the advantages that accurate online time can be obtained even if the user automatically modifies the server system time, the obtained online time of the user is accurate even if the user uses different client time, the interface obtaining time is not required to be frequently called, interaction between the client and the server is reduced, and the efficiency and the accuracy of online time statistics are improved.

Description

Online time length statistics method and device and computer readable storage medium
Technical Field
The present invention relates to the technical field of online time lengths of users, and in particular, to a method and apparatus for online time length statistics, and a computer readable storage medium.
Background
In general, when each client pre-logs in to the target application, login request information is sent to the server, and when the client confirms that login is authorized, a login confirmation message is sent to the client, so that the client can log in to the target application. When the client logs out of the target application, the server also receives notification of the log-out state. The calculation of the user online time length is typically to calculate the difference between the time of first login and the time of last login from the user, thereby calculating the user online time length.
At present, the existing simple calculation method is rough, and the actual online time of the user cannot be accurately calculated. Although the conventional technology at present obtains time through multiple requests and then performs difference calculation to obtain the result of the online time length, each request is sent to occupy the resources of the server, and time judgment is performed each time, which is troublesome and complex.
Disclosure of Invention
In view of this, an object of the embodiments of the present application is to provide a method, an apparatus, and a computer readable storage medium for calculating a difference between a local time of a client when a user logs in and a local time of a server when the user logs in by setting a preset statistical time model, and summing the difference with the difference between the local time of the server when the user invokes an interface for the first time and the local time of the client when the user logs in for the first time, so as to finally calculate an online time of the user; the method and the device have the advantages that under the condition that server resources are not frequently called, accurate online time length of the user can be obtained; when the server time is inconsistent with the client time, accurate user online time can be obtained; the method and the device realize that the user logs in at the server side at different times, and the counted online time is still accurate, so that the technical problems of inaccurate operation, occupation of server resources and complicated processing are solved.
In a first aspect, an embodiment of the present application provides an online time length statistics method, which is applied to a client, where the client is in communication connection with a server; the method comprises the following steps: acquiring the time of a user logging in a server, the local time of the user logging in a client, the time of the first calling of the online time length interface server by the user and the local time of the first logging in of the client from the server; substituting the user login server time, the user login client local time, the user first call online time length interface server time and the user first login client local time into a preset statistical time length model to calculate, and obtaining online time length.
In the implementation process, the accurate online time can be obtained by using the online time counting method applied to the client side, only one-time connection between the client side and the server side is needed, so that the accurate online time can be obtained even if a user automatically modifies the server system time, even if the client side time used by the user is different, the obtained online time of the user is accurate, the interface obtaining time does not need to be frequently called, the interaction between the client side and the server side is reduced, and the efficiency and the accuracy of online time counting are improved.
Optionally, the calculating the user login server time, the user login client local time, the user first call online time length interface server time, and the user first login client local time are substituted into a preset statistical time length model, and after the online time length is obtained, the method further includes: and returning the online time to a server side through the called online time interface for displaying.
In the implementation process, the data are returned to be displayed by calling the online time interface, so that the user experience is improved.
Optionally, the preset statistical duration model includes: the online time length is equal to the sum of the first difference value and the second difference value; the first difference value is the difference between the local time of the user logging in the client and the time of the user logging in the server; the second difference value is the difference between the time when the user calls the online time length interface server for the first time and the local time when the user logs in the client for the first time.
In the implementation process, the difference value between the local time of the client when the user logs in and the local time of the server when the user logs in is summed with the difference value between the local time of the server when the user invokes the interface for the first time and the local time of the client when the user logs in for the first time, so that the online time of the user is finally calculated to be used as the thought of the preset statistical time model, the interface acquisition time does not need to be frequently invoked, the interaction between the client and the server is reduced, and the efficiency and the accuracy of online time statistics are improved.
Optionally, the calculating the user login server time, the user login client local time, the user first call online time length interface server time, and the user first login client local time are substituted into a preset statistical time length model, and after the online time length is obtained, the method further includes: acquiring the increasing time of a preset timer; and according to the increasing time, accumulating and updating the online time.
In the implementation process, the addition of a preset timer for accumulating and updating the online time length can prevent the situation that the final result is inaccurate due to the fact that the local time or the server system time is modified after the user logs in, the situation that the server is lost under the condition of stopping accidentally can be avoided, and the efficiency and the accuracy of online time length statistics are improved.
Optionally, after the online time length is updated in an accumulated manner according to the increasing time, the method further includes: judging whether the time of the user logging in the server is consistent with the local time of the user logging in the client; if the user login server time is inconsistent with the local time of the user login client, determining the user login server time which is calculated by substituting a preset statistical time length model as the user login server time before the inconsistency, and performing time calibration on the online time length.
In the implementation process, the accuracy of the online time length can be further verified through time calibration, the accurate online time length can be obtained only by connecting the client side with the server side once, then the calling interface can be used for time calibration again, the time is more accurate, server resources are not required to be occupied, the accurate online time length can be obtained when the clients in different local time log in, and the efficiency and the accuracy of online time length statistics are improved.
In a second aspect, an embodiment of the present application provides an online time length statistics method, which is applied to a server, where the server is communicatively connected to a client, and the method includes: detecting the login of a user to the client, and creating a database to store the time of the user logging in the server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time; when the checking operation of the user on the online time is detected, an online time interface is called, the user login server time, the user login client local time and the user online time interface calling server time are transmitted to the client, and the client calculates the online time according to a preset statistical time model; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user invokes the online duration interface server time for the first time.
In the implementation process, the accurate online time can be obtained by using the online time counting method applied to the server side only by connecting the client side with the server side once, so that the accurate online time can be obtained even if a user automatically modifies the server system time, even if the user uses different client side time, the obtained online time of the user is accurate, the interface obtaining time does not need to be frequently called, the interaction between the client side and the server side is reduced, and the efficiency and the accuracy of online time counting are improved.
In a third aspect, an embodiment of the present application provides an online time length statistics method, which is applied to a system including a client and a server, where the client is communicatively connected to the server, and the method includes: detecting the login of a user to the client by the server, and creating a database to store the time of the user logging in the server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time; when the server detects the checking operation of the user on the online time, an online time interface is called, the user login server time, the user login client local time and the user call online time interface server time are transmitted to the client, so that the client calculates the online time according to a preset statistical time model; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user calls the time of the online time interface server for the first time; the client acquires the time of a user logging in a server, the local time of the user logging in the client, the time of the user calling the online time interface server for the first time and the local time of the user logging in the client from the server; and substituting the time of the user logging in the server, the local time of the user logging in the client, the time of the first calling of the online time length interface server by the user and the local time of the first logging in the client into a preset statistical time length model by the client for calculation to obtain the online time length.
In the implementation process, by the online time length statistics method applied to the client and the server, a preset statistical time length model based on the client local time when the user logs in, the server system time when the user calls an interface for the first time, the client local time when the user logs in for the first time and the like is set, and finally the online time length of the user is calculated; the method and the device have the advantages that under the condition that server resources are not frequently called, accurate online time length of the user can be obtained; when the server time is inconsistent with the client time, accurate user online time can be obtained; the method has the advantages that the user can log in at the server side at different time or automatically modify the server system time, and the still accurate online time can be counted; interaction between the client and the server is reduced, and the efficiency and accuracy of online time length statistics are improved.
In a fourth aspect, an embodiment of the present application provides an online time length statistics device, which is applied to a client, where the client is communicatively connected to a server, and the device includes: the acquisition module is used for acquiring the time of a user logging in a server, the local time of the user logging in a client, the time of the user calling the online time duration interface server for the first time and the local time of the user logging in the client from the server; and the calculation statistics module is used for substituting the user login server time, the user login client local time, the user first call online time length interface server time and the user first login client local time into a preset statistical time length model to calculate so as to obtain online time length.
In a fifth aspect, an embodiment of the present application provides an online time length statistics device, which is applied to a server, where the server is communicatively connected to a client, and the device includes: the storage module is used for creating a database to store the time of a user logging in a server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time; the calling interface module is used for calling an online time interface and transmitting the user login server time, the user login client local time and the user calling online time interface server time to the client when the user checks the online time so as to calculate the online time; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user invokes the online duration interface server time for the first time.
In a sixth aspect, embodiments of the present application further provide an electronic device, including: a processor, a memory storing machine-readable instructions executable by the processor, which when executed by the processor perform the steps of the method described above when the electronic device is run.
In a seventh aspect, embodiments of the present application provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method described above.
In order to make the above objects, features and advantages of the present application more comprehensible, embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of an online time length statistics method provided in an embodiment of the present application;
fig. 2 is a flow chart of an online time length statistics method provided in an embodiment of the present application;
fig. 3 is a flowchart of an online time length statistics method applied to a client according to an embodiment of the present application;
fig. 4 is a flowchart of an online time length statistics method applied to a server side according to an embodiment of the present application;
Fig. 5 is a schematic functional block diagram of an online time length statistics device applied to a client according to an embodiment of the present application;
fig. 6 is a schematic functional block diagram of an online time length statistics device applied to a server according to an embodiment of the present application;
fig. 7 is a block schematic diagram of an electronic device provided with an online time counting apparatus according to an embodiment of the present application.
Icon: 210-an acquisition module; 220-calculating a statistics module; 230-a storage module; 240-call interface module; 300-an electronic device; 311-memory; 312-a storage controller; 313-processor; 314-peripheral interface; 315-an input-output unit; 316-display unit.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, are intended to be within the scope of the present application.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element. The terms "first," "second," and the like are used merely to distinguish between descriptions and are not to be construed as indicating or implying relative importance.
The inventor of the present application notes that, in the conventional technology, the online time length result is calculated by multiple requests to obtain time and then performing a difference, for example, in the prior art, a technical scheme based on java statistics for online time length of a user is mentioned, and the scheme specifically may include: 1. the server sets an effective time interval value for calculating the online time of the user, and assigns the online time of the user to zero; 2. the user sends a request to the server through the browser; 3. the server records the sending request time of the user, and the time interval value is obtained by subtracting the last sending request time from the sending request time; 4. if the time interval value is smaller than or equal to the effective time interval value, the server accumulates the time interval value into the online time of the user; 5. the user sends a request to the server through the browser again, and the step 3 and the step 4 are repeatedly executed; 6. the server is provided with a timer, the timer sends a prompt to the server, and the server stores the online time length of the user and the last sending request time into a database after receiving the prompt; 7. the timer sends a time reminder to the server at fixed time intervals; 8. the server persistently stores the user online time and the last transmission request time in a database.
The scheme is based on the fact that a user makes multiple access request operations on a browser, then a server judges whether the time interval of the user sending the request is within the effective time interval, and the calculated online time length is calculated. When the online time length of the user is calculated, although the accurate time length can be calculated, the timer sends a prompt to the server to occupy the resources of the server, so that a certain performance problem exists. Moreover, if the user does not frequently send requests, the technical scheme is not applicable, and the online time is not accurate enough. In addition, the user online time calculated by this method is less accurate if the user modifies the time on the server. In view of this, the embodiment of the application provides an online time length counting method as described below.
Referring to fig. 1, fig. 1 is a flowchart of an online time length statistics method according to an embodiment of the present application. The specific flow of this embodiment is explained in detail below. The online time length counting method is applied to a system comprising a client and a server, wherein the client is in communication connection with the server, and the method comprises the following steps: step 100, step 120, step 140 and step 160.
Step 100: the server detects the login of the user to the client, and when the user logs in the client, a database is created to store the time for logging in the server by the user and the local time for logging in the client by the user; the local time for the user to log in the client side comprises the following steps: the user logs in the local time of the client for the first time;
step 120: when the checking operation of the user on the online time is detected, the server side calls an online time interface and transmits the time of the user logging in the server and the local time of the user logging in the client side as well as the time of the user calling the online time interface server to the client side, so that the client side calculates the online time according to a preset statistical time model; wherein, the calling of the on-line duration interface server time by the user comprises the following steps: the user calls the time of the online time interface server for the first time;
step 140: the client acquires the time of a user logging in a server, the local time of the user logging in the client, the time of the user calling the online time duration interface server for the first time and the local time of the user logging in the client from the server;
step 160: and substituting the user login server time, the user login client local time, the user first call online time length interface server time and the user first login client local time into a preset statistical time length model by the client to calculate so as to obtain the online time length.
The system architecture may include, for example, a server side (server side) and a plurality of clients communicatively coupled to the server side. The plurality of clients may be: any terminal device, for example: any terminal equipment such as mobile phones, notebooks, computers, personal digital assistants (English: personal Digital Assistant, PDA), vehicle-mounted computers and the like; the operating system of the terminal device may be: the Windows series operating system, unix operating system, linux operating system, mac operating system and the like can be used for processing and responding to operations such as login of a client, checking on-line time length and the like. The server side may be: recording login (English: log) state, logout (English: logo) state, calling on-line time interface state and the like of each client, and counting the login (English: log) state, logout (English: logo) state, calling on-line time interface state and the like of each client to a server hardware system in an event log table; the server hardware system can be run and executed by the operating systems at the software level; in the event log table, all events can be orderly arranged according to the time sequence corresponding to the user login state, the log-out state and the calling on-line time interface state, and the server side can select the client side in the target time period for monitoring and is used for counting the actual on-line time. The preset statistical duration model may be: according to the real-time recorded during the interaction between the server and the client, such as login state, logout state, calling on-line time interface state, etc., as the variable, the mathematical statistical model for calculating on-line time is set, for example: the difference between the local time of the client when the user logs in and the server system time when the user logs in is summed with the difference between the server system time when the user calls the interface for the first time and the local time of the client when the user logs in for the first time. The local time when the user logs in to the client for the first time can be considered as: only in case the logged-in user has logged out, the next login belongs to the first login, at which time the local time of the client is recorded. Similarly, the first time the user invokes the interface server may be considered to be: the first call interface only belongs to the first call interface under the condition of the next login or the first login after the logged-in user logs out each time, and the server system time is recorded at the moment.
When each client user logs in the target application, login request information is sent to the server, and after the client confirms authorized login, login confirmation information is sent to the client, so that the client can log in the target application; when the client clicks the online time button to check the online time and log out the target application, the server side can also receive a notification of calling the online time interface state and the log-out state because the request for calling the Web service interface can be initiated by clicking the online time button to check the online time. Wherein the target application may include: gaming applications, music applications, video entertainment applications, learning applications, social applications, and the like.
As shown in fig. 2, when a user logs in at a certain target application of the client, the server records the local time loginTime of the user logging in the client and the server system time (user logging in server time) when logging in; when a user checks the online time, a Web service interface is called, and the interface transmits the local time loginTime of the user logging in the client and the system time system of the server when the interface is called to the client for the client to use; after the client obtains the local time loginTime of the user login client returned by the server, the client performs user online time calculation according to a preset statistical time model (statistical formula) by combining the server system time during login and the server system time system when an interface is called, and then takes the calculated result as the actual online time.
Setting a preset statistical duration model based on the local time of the client when the user logs in, the server system time when the user calls an interface for the first time, the local time of the client when the user logs in for the first time and the like by the online duration statistical method applied to the client and the server, and finally calculating the online duration of the user; the method and the device have the advantages that under the condition that server resources are not frequently called, accurate online time length of the user can be obtained; when the server time is inconsistent with the client time, accurate user online time can be obtained; the method has the advantages that the user can log in at the server side at different time or automatically modify the server system time, and the still accurate online time can be counted; interaction between the client and the server is reduced, and the efficiency and accuracy of online time length statistics are improved.
Referring to fig. 3, fig. 3 is a flowchart of an online time length counting method applied to a client according to an embodiment of the present application, and a detailed explanation of a specific flow of the embodiment is provided below. The method is applied to the client, the client is in communication connection with the server, and the method can comprise the following steps: step 141 and step 142.
Step 141: obtaining user login server time, user login client local time, user first call online time interface server time and user first login client local time from a server side;
step 142: substituting the time of the user logging in the server, the local time of the user logging in the client, the time of the first calling of the online time length interface server by the user and the local time of the first logging in the client into a preset statistical time length model for calculation, and obtaining the online time length.
Illustratively, the online time period may be: the user login starting time plays a role in duration statistics when the online duration is currently checked. The preset statistical duration model may be: and the mathematical statistical model for calculating the online time is set according to real-time such as the user login server time, the user login client local time, the first time online time interface server time called by the user, the first time online time local time logged by the user and the like acquired by the server side as variables. The local time of the user logging in the client for the first time can be: the local time recorded when the logged-in user logs in the next time under the logout condition is met in the local time of a plurality of user login client sides stored by the server side; the first time the user invokes the interface server may be: the server system time recorded by the interface is called for the first time under the condition that the user logs in next time or logs in for the first time after logging out each time in the server time of the interface of the multiple calling on-line time length stored in the server.
When a user logs in the controller from the server, the login time of the server system and the local time of the client of the user are recorded at the same time, and the login time of the two users are stored in the database. After the user logs in, when the user wants to check the online time, the login time and the time of the system at the moment are returned to the front end together and processed by the front end. The client calculates by calling the interface and adopting a preset statistical time length model, specifically, the local time of the login client is subtracted from the server system time, and then the result of subtracting the first login server time returned by the server from the local time of the first call of the interface client is added, so that the online time length of the user can be finally obtained.
By using the online time length counting method applied to the client, the accurate online time length can be obtained only by connecting the client with the server at one time, so that the accurate online time length can be obtained even if a user automatically modifies the system time of the server, the obtained online time length of the user is accurate even if the user uses different client time, the interface obtaining time does not need to be frequently called, the interaction between the client and the server is reduced, and the efficiency and the accuracy of online time length counting are improved.
In one embodiment, after step 142, further comprises: step 143.
Step 143: and returning the online time to the server side through the called online time interface for displaying.
Illustratively, the online time duration interface may be an API (application programmable) interface that invokes a server to acquire related data when detecting a user's viewing operation of the online time duration at the client, for example: the web interface is used for displaying resources returned by the server when the web interface requests to display a page with the online time length, wherein the resources comprise HTML, CSS and JS, and besides, the server can also return resources of the types of pictures, videos, fonts, plugins and the like, and all the resources are transmitted by the HTTP protocol. The HTTP protocol is a transmission protocol for transmitting hypertext from a world wide web (www) server to a local browser, the HTTP transfers relevant time data based on a TCP/IP communication protocol, and the HTTP protocol works on a client-server architecture, and the browser sends a request as a client to an HTTP server (i.e., a web server) through url. Therefore, as shown in fig. 2, the web interface capable of calling the online time length transmits the online time length data calculated at the client to the server through the HTTP protocol for display, and finally, only the processed data is required to be displayed on the display interface requested by the web interface, and the time is gradually increased along with the login time of the user. And the data is returned to be displayed by calling the online time interface, so that the user experience is improved.
In one embodiment, the preset statistical duration model includes: the online time length is equal to the sum of the first difference value and the second difference value; the first difference value is the difference between the local time of the user logging in the client and the time of the user logging in the server; the second difference is the difference between the time when the user calls the online time duration interface server for the first time and the local time when the user logs in the client for the first time.
Illustratively, the preset statistical duration model may be: the mathematical statistical model for calculating the online time length set according to the above four times as variables may specifically be: the difference between the local time of the client when the user logs in and the system time of the server when the user logs in is summed with the difference between the system time of the server when the user calls the interface for the first time and the local time of the client when the user logs in for the first time, and the expression can be expressed as: online time= ((client local time when user logged in-server time when user logged in) + (server time when user first invokes interface-client local time when user first logged in)). The local time of the client when the user logs in is a dynamic value, and refers to the local time at the moment of logging in, and the local time changes along with the change of the local time of the client; when the online time length of a user logging in for the first time is counted, the first two terms of the formula are dynamic values, and the last two terms are fixed values, namely the server time when the user calls an interface for the first time and the client local time when logging in for the first time are fixed values.
The method and the device have the advantages that the difference value between the local time of the client when the user logs in and the server system time when the user logs in is summed with the difference value between the server system time when the user calls the interface for the first time and the local time of the client when the user logs in for the first time, the online time of the user is finally calculated to be used as the thought of a preset statistical time model, the interface acquisition time does not need to be frequently called, interaction between the client and the server is reduced, and the efficiency and the accuracy of online time statistics are improved.
In one embodiment, step 140 further comprises, after: step 144 and step 145.
Step 144: acquiring the increasing time of a preset timer;
step 145: and according to the increasing time, performing accumulated updating on the online time.
In one embodiment, the server may be preset with a timer plug-in, the timer may send a time alert to the server, and after the server receives the time alert, the server persistently stores the online time of the user and the time of the timer acquired by the last sending request in the database, so as to avoid data loss caused by the server in the event of unexpected termination. Optionally, as shown in fig. 2, the timer sends a time alert to the server at fixed time intervals, where the time alert includes a new time added after the client finishes obtaining the online time according to the preset statistical time model. The method is equivalent to that after the client finishes processing the four time data, a timer is additionally used, and 1 is added to the counted on-line time per second, 1 minute is added to 60 seconds, 1 hour is added to 60 minutes, 1 day is added to 24 hours, and the like.
The addition of a preset timer for accumulating and updating the online time length can prevent the situation that the final result is inaccurate by modifying the local time or the server system time after the user logs in, and can also avoid the situation that the server loses data under the condition of unexpected termination, thereby improving the efficiency and the accuracy of online time length statistics.
In one embodiment, step 145 further comprises, after: step 146 and step 147.
Step 146: judging whether the time of the user logging in the server is consistent with the local time of the user logging in the client;
step 147: if the user login server time is inconsistent with the local time of the user login client, determining the user login server time calculated by substituting the preset statistical time length model as the user login server time before the inconsistency, and performing time calibration on the online time length.
Illustratively, when the server system time or the client local time is artificially modified, the client local time and the server system time may not be consistent, where: the local time of the client is 10:00, the system time of the server is 11:00, if the time is not required to be calibrated, the situation may occur that the user just logs in the server, the online time of the user is a negative number, or the online time is already hours or days, that is, the counted online time of the user is error, so that the time is required to be calibrated.
The calibration method can be as follows: substituting the modified server system time or the client local time into a preset statistical time length model to calculate the online time length, updating by a timer, and then calculating the online time length without using the modified server system time or the client local time. For example: the verification process may be: assume that the client local time when the user logs in: 10:00, server system time when user logs in: 11:00, the two are inconsistent, and the system time when the user calls the user on-line duration interface for the first time: 12:00, the statistical time length model is obtained through the preset: ((10-11) + (12-10))=1, at which point it can be seen that the user online time has been 1 hour, obviously inaccurately. Therefore, after the online time is calculated by substituting the server system time before modification or the client local time data into the model, the online time is updated according to the timer, and repeated calculation is not needed by using the modified server time.
The accuracy of the online time length can be further verified through time calibration, the accurate online time length can be obtained only by connecting the client side with the server side once, then the calling interface can be used for time accuracy again, time is more accurate, server resources are not required to be occupied, accurate online time length can be obtained when the clients of different local time log in, and the efficiency and accuracy of online time length statistics are improved.
Referring to fig. 4, fig. 4 is a flowchart of an online time length statistics method applied to a server according to an embodiment of the present application, and a detailed explanation of a specific flow of the embodiment is provided below. The method is applied to a server side, the server side is in communication connection with a client side, and the method can comprise the following steps: step 101 and step 102.
Step 101: detecting the login of a user to a client, and creating a database to store the time of the user logging in a server and the local time of the user logging in the client when the user logs in the client; the local time for the user to log in the client side comprises the following steps: the user logs in the local time of the client for the first time;
step 102: when the checking operation of the user on the online time is detected, an online time interface is called, and the time of the user logging in the server, the local time of the user logging in the client and the time of the user calling the online time interface server are transmitted to the client, so that the client calculates the online time according to a preset statistical time model; wherein, the calling of the on-line duration interface server time by the user comprises the following steps: the user invokes the online duration interface server time for the first time.
Illustratively, the first time the user logs into the client local time may be: the local time recorded when the logged-in user logs in the next time under the logout condition is met in the local time of a plurality of user login client sides stored by the server side; the first time the user invokes the interface server may be: the server system time recorded by the interface is called for the first time under the condition that the user logs in next time or logs in for the first time after logging out each time in the server time of the interface of the multiple calling on-line time length stored in the server.
When a user logs in for the first time at a certain target application of the client, the server creates a database to store login time (user login server time and user login client local time) for use in counting online time of the user. When the user checks the online time, a web interface is called, and the interface transmits the two times and the server system time when the user calls the interface to the client for the client to use, so as to calculate and effectively calibrate the online time of the user. The preset statistical time length model can be expressed as follows by a mathematical formula: ((client local time when user logged in-system time when user logged in) + (server time when user first invokes interface-client local time when user first logged in)).
By using the online time length counting method applied to the server side, the accurate online time length can be obtained only by connecting the client side with the server side once, so that the accurate online time length can be obtained even if a user automatically modifies the system time of the server, the obtained online time length of the user is accurate even if the user uses different client side time, the interface obtaining time does not need to be frequently called, the interaction between the client side and the server side is reduced, and the efficiency and the accuracy of online time length counting are improved.
Referring to fig. 5, fig. 5 is a schematic block diagram of an online time length statistics device applied to a client, where the client is communicatively connected to a server, and the device includes: an acquisition module 210 and a calculation statistics module 220.
The obtaining module 210 is configured to obtain, from the server, a user login server time, a user login client local time, a user first call online duration interface server time, and a user first login client local time;
the calculation statistics module 220 is configured to substitute the user login server time, the user login client local time, the user first call online time length interface server time, and the user first login client local time into a preset statistical time length model to perform calculation, so as to obtain online time length.
Alternatively, the calculation statistics module 220 may be configured to:
and returning the online time to the server side through the called online time interface for displaying.
Optionally, the preset statistical duration model includes: the online time length is equal to the sum of the first difference value and the second difference value; the first difference value is the difference between the local time of the user logging in the client and the time of the user logging in the server; the second difference is the difference between the time when the user calls the online time duration interface server for the first time and the local time when the user logs in the client for the first time.
Alternatively, the calculation statistics module 220 may be configured to:
acquiring the increasing time of a preset timer;
and according to the increasing time, performing accumulated updating on the online time.
Alternatively, the calculation statistics module 220 may be configured to:
judging whether the time of the user logging in the server is consistent with the local time of the user logging in the client;
if the user login server time is inconsistent with the local time of the user login client, determining the user login server time calculated by substituting the preset statistical time length model as the user login server time before the inconsistency, and performing time calibration on the online time length.
Referring to fig. 6, fig. 6 is a schematic block diagram of an online time length statistics device applied to a server, where the server is communicatively connected to a client, and the device includes: a storage module 230 and a call interface module 240.
The storage module 230 is configured to create a database to store a user login server time and a user login client local time when the user logs in to the client; the local time for the user to log in the client side comprises the following steps: the user logs in the local time of the client for the first time;
the calling interface module 240 is configured to call an online time interface and transfer a user login server time, a user login client local time, and a user calling online time interface server time to the client when the user views the online time, so as to calculate the online time; wherein, the calling of the on-line duration interface server time by the user comprises the following steps: the user invokes the online duration interface server time for the first time.
Referring to fig. 7, fig. 7 is a block schematic diagram of an electronic device. The electronic device 300 may include a memory 311, a memory controller 312, a processor 313, a peripheral interface 314, an input output unit 315, a display unit 316. It will be appreciated by those of ordinary skill in the art that the configuration shown in fig. 7 is merely illustrative and is not intended to limit the configuration of the electronic device 300. For example, electronic device 300 may also include more or fewer components than shown in FIG. 7, or have a different configuration than shown in FIG. 7.
The above-mentioned memory 311, memory controller 312, processor 313, peripheral interface 314, input/output unit 315, and display unit 316 are electrically connected directly or indirectly to each other to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines. The processor 313 is used to execute executable modules stored in the memory.
The Memory 311 may be, but is not limited to, a random access Memory (Random Access Memory, RAM), a Read Only Memory (ROM), a programmable Read Only Memory (Programmable Read-Only Memory, PROM), an erasable Read Only Memory (Erasable Programmable Read-Only Memory, EPROM), an electrically erasable Read Only Memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc. The memory 311 is configured to store a program, and the processor 313 executes the program after receiving an execution instruction, and a method executed by the electronic device 300 defined by the process disclosed in any embodiment of the present application may be applied to the processor 313 or implemented by the processor 313.
The processor 313 may be an integrated circuit chip having signal processing capabilities. The processor 313 may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (digital signal processor, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field Programmable Gate Arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The peripheral interface 314 couples various input/output devices to the processor 313 and the memory 311. In some embodiments, the peripheral interface 314, the processor 313, and the memory controller 312 may be implemented in a single chip. In other examples, they may be implemented by separate chips.
The input/output unit 315 is used for providing input data to a user. The input/output unit 315 may be, but is not limited to, a mouse, a keyboard, and the like.
The display unit 316 provides an interactive interface (e.g., a user interface) between the electronic device 300 and a user for reference. In this embodiment, the display unit 316 may be a liquid crystal display or a touch display. The liquid crystal display or the touch display may display a process of executing the program by the processor.
The electronic device 300 in the present embodiment may be used to perform each step in each method provided in the embodiments of the present application.
Furthermore, the embodiments of the present application also provide a computer readable storage medium, on which a computer program is stored, which when being executed by a processor performs the steps in the above-described method embodiments.
The computer program product of the above method provided in the embodiments of the present application includes a computer readable storage medium storing a program code, where instructions included in the program code may be used to perform steps in the above method embodiment, and specifically, reference may be made to the above method embodiment, which is not described herein.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The above-described apparatus embodiments are merely illustrative, and the division of the modules is merely a logical function division, and there may be additional divisions when actually implemented, and for example, multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, device or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form. The functional modules in the embodiments of the present application may be integrated together to form a single part, or each module may exist alone, or two or more modules may be integrated to form a single part.
It should be noted that the functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM) random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application, and various modifications and variations may be suggested to one skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims (10)

1. The online time length counting method is characterized by being applied to a client, wherein the client is in communication connection with a server; the method comprises the following steps:
acquiring the time of a user logging in a server, the local time of the user logging in a client, the time of the first calling of the online time length interface server by the user and the local time of the first logging in of the client from the server;
substituting the user login server time, the user login client local time, the user first call online time length interface server time and the user first login client local time into a preset statistical time length model to calculate, and obtaining online time length.
2. The method according to claim 1, wherein after substituting the user login server time, the user login client local time, the user first call online time duration interface server time, and the user first login client local time into a preset statistical time duration model to calculate, the method further comprises:
And returning the online time to a server side through the called online time interface for displaying.
3. The method of claim 1, wherein the predetermined statistical duration model comprises: the online time length is equal to the sum of the first difference value and the second difference value;
the first difference value is the difference between the local time of the user logging in the client and the time of the user logging in the server; the second difference value is the difference between the time when the user calls the online time length interface server for the first time and the local time when the user logs in the client for the first time.
4. The method according to claim 1, wherein after substituting the user login server time, the user login client local time, the user first call online time duration interface server time, and the user first login client local time into a preset statistical time duration model to calculate, the method further comprises:
acquiring the increasing time of a preset timer;
and according to the increasing time, accumulating and updating the online time.
5. The method of claim 4, wherein after the accumulating updates to the online time period according to the increasing time, the method further comprises:
Judging whether the time of the user logging in the server is consistent with the local time of the user logging in the client;
if the user login server time is inconsistent with the local time of the user login client, determining the user login server time which is calculated by substituting a preset statistical time length model as the user login server time before the inconsistency, and performing time calibration on the online time length.
6. The online time length counting method is characterized by being applied to a server, wherein the server is in communication connection with a client, and the method comprises the following steps:
detecting the login of a user to the client, and creating a database to store the time of the user logging in the server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time;
when the checking operation of the user on the online time is detected, an online time interface is called, the user login server time, the user login client local time and the user online time interface calling server time are transmitted to the client, and the client calculates the online time according to a preset statistical time model; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user invokes the online duration interface server time for the first time.
7. An online time length counting method, which is applied to a system comprising a client and a server, wherein the client is in communication connection with the server, and the method comprises the following steps:
detecting the login of a user to the client by the server, and creating a database to store the time of the user logging in the server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time;
when the server detects the checking operation of the user on the online time, an online time interface is called, the user login server time, the user login client local time and the user call online time interface server time are transmitted to the client, so that the client calculates the online time according to a preset statistical time model; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user calls the time of the online time interface server for the first time;
the client acquires the time of a user logging in a server, the local time of the user logging in the client, the time of the user calling the online time interface server for the first time and the local time of the user logging in the client from the server;
And substituting the time of the user logging in the server, the local time of the user logging in the client, the time of the first calling of the online time length interface server by the user and the local time of the first logging in the client into a preset statistical time length model by the client for calculation to obtain the online time length.
8. An online time length counting device, which is applied to a client, wherein the client is in communication connection with a server, and the device comprises:
the acquisition module is used for acquiring the time of a user logging in a server, the local time of the user logging in a client, the time of the user calling the online time duration interface server for the first time and the local time of the user logging in the client from the server;
and the calculation statistics module is used for substituting the user login server time, the user login client local time, the user first call online time length interface server time and the user first login client local time into a preset statistical time length model to calculate so as to obtain online time length.
9. An online time length counting device, which is applied to a server, wherein the server is in communication connection with a client, and the device comprises:
The storage module is used for creating a database to store the time of a user logging in a server and the local time of the user logging in the client when the user logs in the client; wherein, the local time of the user logging in the client side comprises the following steps: the user logs in the local time of the client for the first time;
the calling interface module is used for calling an online time interface and transmitting the user login server time, the user login client local time and the user calling online time interface server time to the client when the user checks the online time so as to calculate the online time; wherein, the time of the user calling the on-line duration interface server comprises the following steps: the user invokes the online duration interface server time for the first time.
10. A computer-readable storage medium, characterized in that it has stored thereon a computer program which, when executed by a processor, performs the steps of the method according to any of claims 1 to 4.
CN202211643054.0A 2022-12-20 2022-12-20 Online time length statistics method and device and computer readable storage medium Pending CN116132500A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211643054.0A CN116132500A (en) 2022-12-20 2022-12-20 Online time length statistics method and device and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211643054.0A CN116132500A (en) 2022-12-20 2022-12-20 Online time length statistics method and device and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN116132500A true CN116132500A (en) 2023-05-16

Family

ID=86298412

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211643054.0A Pending CN116132500A (en) 2022-12-20 2022-12-20 Online time length statistics method and device and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN116132500A (en)

Similar Documents

Publication Publication Date Title
US8266281B1 (en) Collecting client-side performance metrics and latencies
CN111459783B (en) Application program optimization method and device, electronic equipment and storage medium
EP2890077A1 (en) Method and apparatus for acquiring dynamic message
CN112115026A (en) Server cluster monitoring method and device, electronic equipment and readable storage medium
US7711518B2 (en) Methods, systems and computer program products for providing system operational status information
CN111930454B (en) Interface display method and device, terminal equipment and medium
CN112463254A (en) Method, device and equipment for acquiring webpage loading time and storage medium
CN112671566A (en) Data processing method and device, computer equipment and readable storage medium
US10853359B1 (en) Data log stream processing using probabilistic data structures
CN110119334B (en) Page script monitoring method and device
CN104462116B (en) Data selection method and device
CN116132500A (en) Online time length statistics method and device and computer readable storage medium
CN116471174B (en) Log data monitoring system, method, device and storage medium
CN109889614B (en) Information pushing method and device
CN108964947A (en) Background service quality determining method and device, computer equipment
CN116521694A (en) Data maintenance method, intelligent terminal and storage medium
CN116545905A (en) Service health detection method and device, electronic equipment and storage medium
CN111629005A (en) Anti-cheating method and device, electronic equipment and storage medium
CN111431764A (en) Node determination method, device, system and medium
CN114968696A (en) Index monitoring method, electronic equipment and chip system
CN111459743B (en) Data processing method and device and readable storage medium
CN115758300B (en) Data processing method, device, electronic equipment and storage medium
EP3273354A1 (en) Effect of operations on application requests
CN114510704B (en) Risk detection method and device, computing equipment and computer storage medium
CN111224936B (en) User abnormal request detection method, system, device and machine readable medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination