Home > Net >  C # List stored per hour of statistics, if there is no information, the hour is new information
C # List stored per hour of statistics, if there is no information, the hour is new information

Time:03-25

Hi,

I have a Alist, used to store the Info Class,

 
Public class Info
{
Public int data {get; set; }
Public DateTime startTime {get; set; }//for instance: the 2021-03-24 10:00:00
Public DateTime endTime {get; set; }//for instance: the 2021-03-24 11:00:00
}


Assuming AList need to store 2 (not necessarily the 12 o 'clock in the morning) hourly data, a total of 48 elements, even if the value is 0 also need to record,
Now has a BList entities within 2 days after the data, about 4 pens in this 4 pen data is valid (non-zero data),
Hope will be within the data storage to AList BList,

Now think of is...

 

//1. The first build AList of all the data, the data is 0
DateTime startTime=DateTime. Parse (" 2020/07/07 00:00:01 ");//start time
DateTime endTime=DateTime. Parse (" 2020/07/09 00:00:00 ");//end time
List AList=new List (a);//store all period of time the hour
Double pump=int. Parse (math.h Floor ((endTime - startTime). TotalHours). The ToString ());//calculate period of hours
Int hourBegin=startTime. Hour;//start time hour
String daybegin=startTime. Date. The ToString ();//start time date
DateTime hourTimeBegin=DateTime. Parse (daybegin + + hourBegin + ', '+' "00" + + "00" ':');//convert the start time of hours
If (pump & gt; 1)/hours/whether time is greater than 1
{
For (int I=1; I & lt;=hours; I++)
{
The Info Info=new Info ();
Info. Data=https://bbs.csdn.net/topics/0;
Info. StartTime=hourTimeBegin. AddHours (I);

AList. Add (info);
}

//2. Individually than BList

for (int i=0; I & lt; AList. Count; I++)
{
For (int j=0; J & lt; BList. Count; J++)
{
If (DateTime.Com pare said (AList [I] startTime, BList [j]. Journal of startTime)
{
AList [I]. Data=https://bbs.csdn.net/topics/BList [j]. Journal of data;
}
}
}
}



Think of double circle time complexity is too high...
Don't know whether there is any faster way?
Please board advanced guidance, thank you ^ ^


CodePudding user response:

Assume that your software is never restart
You can baidu "c # cache depend on" set absolute expiration time for 48 hours, after the expiration himself out

If you need to restart the software, please baidu "redis' special cache pieces such as


CodePudding user response:

reference 1st floor wanghui0380 response:
never assume that your software restart
You can baidu "c # cache depend on" set absolute expiration time for 48 hours, after the expiration himself out

If you need to restart the software, please baidu "redis' special cache pieces such as


Wanghui0380 hello, actually BList data taken from the database, so there's no use redis who, just want a simple algorithm to handle data,
  •  Tags:  
  • C#
  • Related