How to fast enumerate and compare objects of many NSArrays in Objective-C? - iphone

I have many different NSArray's stored in .dat files, in the Documents folder of my iPhone application, like so:
john.dat
mary.dat
bob.dat etc...
The number of .dat files is unknown and it will increase or decrease according to a number of factors related to the user's manipulation of the app.
What are the contents of these NSArray's stored in the.dat files? They contain NSString's. It is important to say that the countfor each NSArray my vary, like so:
john.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
"Wed, 13 Jun 2012 04:52:30 GMT",
"Thu, 07 Jun 2012 04:52:00 GMT",
mary.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
bob.dat Contains this array of strings:
"Mon, 11 Jun 2012 04:52:06 GMT",
"Tue, 12 Jun 2012 04:51:59 GMT",
"Wed, 13 Jun 2012 04:52:30 GMT",
"Thu, 07 Jun 2012 04:52:00 GMT",
"Fri, 08 Jun 2012 04:51:59 GMT",
"Sun, 10 Jun 2012 04:50:55 GMT"
etc..
I have to periodically verify if each NSString of these NSArray's has been modified, to notify the user of certain events. After doing a XML parsing from the Internet I'm already able to have in memory the new NSArray's corresponding to its respective .dat file previously stored in the Documents folder.
Since I have many .dat files, my question is:
How do I compare EFFICIENTLY AND AT ONCE the new NSArray's (NSArray *john, *mary, *bob, etc...) that I have in memory (as a result of this XML parsing), with the old ones stored in its corresponding john.dat, mary.dat, bob.dat, etc... files in the Documents folder and notify the user if any of the NSString's ("Mon, 11 Jun 2012 04:52:06 GMT","Tue, 12 Jun 2012 04:51:59 GMT", etc...) has been modified?
Thanks for your help!

If you're happy to change the format of your .dat file you could compute a hash of each array's contents and store that at the beginning of the file. When you get new data you can compute its hash and compare that with the hash stored in your file.
Your choice of hashing function will determine the computational efficiency, but the I/O would be minimized.

Well, if you content with storing your arrays as .dat files (with NSKeyedArchiver I'm guessing), then Martin's answer is probably best and the tried and true method of comparison
The approach I might take is to store the NSStrings in NSDictionarys instead of NSArrays. Then you could set an observer on its values, so when an string is pulled from the XML file you compare, replace if necessary and the observer will be called so you can notify the user (see NSNotificationCenter and KVO if not already familiar).
It may also be beneficial (usually is) to store your strings in CoreData as opposed to .dat files, then you could configure an NSFetchedResultsController to keep an eye on your data and do the above when new data is fetched.

Related

mongodb searching for date strings in a range

I have a DB with entries in Universal Time such as this:
{"problemDate": "Mon May 11 2020 13:09:14 GMT+0000 (Coordinated Universal Time)"},
{"problemDate": "Mon May 11 2020 13:09:14 GMT+0000 (Coordinated Universal Time)"},
{"problemDate": "Mon Dec 07 2020 14:08:26 GMT+0000 (Coordinated Universal Time)"},
{"problemDate": "Tue May 12 2020 00:18:21 GMT+0000 (Coordinated Universal Time)"}
Although, I am trying to query for a range of dates, my db has around 2k entries with dates ranging from May to December. If I query for dates greater than December 7th, my return still shows dates such as Mon May 11. I believe this is because my dates are just strings. I was wondering if there is a work around to this. Any help would be appreciated.
This was my query:db.problem.find({"problemDate":{ $gte:("Mon Dec 07 2020 14:08:24 GMT+0000 (Coordinated Universal Time)") }});
You could try an update on the collection to convert the dates from string to IsoDate.
The following script it's designed to run in a mongo shell, and it's assumed that you have selected the database (use databasename) and your collection name is 'datestest':
db.getCollection('datestest').find({}).forEach( function(item){
if (typeof(item.problemDate) == "string"){
print(item.problemDate);
item.problemDate = new Date(item.problemDate);
db.getCollection('datestest').save(item);
}
}
);
You can first save the "bad dates" to a different collection to check the update it's all right, just replace the save item with a diffrerent collection name:
db.getCollection('datestest_check').save(item);

How to simplify this spreadsheet formula?

I am working on my personal financial spreadsheet, and I have one table that lists columns like: "Month","Income",Expense","Notes", and I am building a 2nd table to use to build a new chart so I can view Year over Year comparisons to the data (ie, I will get all of the Januarys' data charted next to each other to compare).
Here is the formula I'm using to transpose this data, but I know there has to be a better way, but my searching is failing me:
=arrayformula({
filter(B5:B64,MONTH(B5:B64)=1);
filter(B5:B64,MONTH(B5:B64)=2);
filter(B5:B64,MONTH(B5:B64)=3);
filter(B5:B64,MONTH(B5:B64)=4);
filter(B5:B64,MONTH(B5:B64)=5);
filter(B5:B64,MONTH(B5:B64)=6);
filter(B5:B64,MONTH(B5:B64)=7);
filter(B5:B64,MONTH(B5:B64)=8);
filter(B5:B64,MONTH(B5:B64)=9);
filter(B5:B64,MONTH(B5:B64)=10);
filter(B5:B64,MONTH(B5:B64)=11);
filter(B5:B64,MONTH(B5:B64)=12)
})
This just seems so unwieldy, though it does what I want. Any suggestions on how to simplify this a bit?
EDIT: for clarifications, I'm taking data that is like: Jan 2015; Feb 2015; Mar 2015; etc, and transposing it to: Jan 2015; Jan 2016; Jan 2017; Feb 2015; Feb 2016; Feb 2017 etc.
Formula
=ARRAY_CONSTRAIN(SORT({B5:B64,MONTH(A1:A24)},2,TRUE),COUNTA(B5:B64),1)
Explanation
{B2:B64,MONTH(B5:B64)} is a custom array of two columns, the input and a column of months.
The SORT function sorts the custom array
The ARRAY_CONSTRAIN function removes the column of months.

MongoDB/mongoose some dates as EDT and others as EST

When getting some records, I'm seeing that some dates are showing as GMT-0400 (EDT) and others are GMT-0500 (EST).
Dates are being added in mongoose simply by using Date.now in the schema.
Any ideas what could cause the offsets to be different?
Edit: Here's an example:
Stored as: ISODate("2015-10-30T15:36:47.287Z") Returned as: Fri Oct 30 2015 11:36:47 GMT-0400 (EDT) using find() with Mongoose
Stored as: ISODate("2015-11-07T14:44:47.956Z") Returned as: Sat Nov 07 2015 09:44:47 GMT-0500 (EST) using find() with Mongoose
It's just the default string representation of the underlying UTC timestamp, showing the timestamp in the local time zone that was in effect at the time.
In 2015, daylight saving time ended at 2:00 AM on Nov 1, so that's why the first one is shown in EDT and the second one is shown in EST.
Any queries you do are always performed using UTC time.

twitter4j - setSince and setUntil don't work

I'm having problem to filter tweets by specifics dates, using setUntil come no tweets, using setSince come recently tweets.. The code is following and after that the output result..
public void readTweetFromKeyword(String keywordString) throws TwitterException
{
twitter4j.Query query =new twitter4j.Query("#clt20");
QueryResult result;
query.setSince("2014-12-12");
int cont = 0;
result = twitter.search(query);
for (Status status : result.getTweets() )
{
System.out.print("original "+status.getId());
System.out.println("\t\tdata "+status.getCreatedAt());
if(!status.getText().substring(0, 2).equals("RT")){
System.out.println(status.getText());
cont++;
}
}
System.out.println(result.getTweets().size());
System.out.println("cont = "+cont);
return;
}
CONSOLE:
original 619433499116896256 data Fri Jul 10 06:10:29 GMT-03:00 2015
If the #BCCI is looking for an alternative to #Clt20, then how about a
league of teams consisting of only Indian players ?
original 619408117495939072 data Fri Jul 10 04:29:37 GMT-03:00 2015
#TesT, #ODI, #T20I, #IPL, #CLT20 Live record, score, history shedule ke lia, Follow #PTV_SpOrtsOne snt to 40404.
original 619330143258050560 data Thu Jul 09 23:19:47 GMT-03:00 2015
Need 66 From 6 Balls. Kinda Impossible #clt20
original 619301555532120065 data Thu Jul 09 21:26:11 GMT-03:00 2015
Kamran Akmals feet are stuck #soshit #CLT20
original 619095093962608640 data Thu Jul 09 07:45:47 GMT-03:00 2015
original 619095079983017984 data Thu Jul 09 07:45:43 GMT-03:00 2015
original 619095051524665344 data Thu Jul 09 07:45:37 GMT-03:00 2015
original 619095028304973825 data Thu Jul 09 07:45:31 GMT-03:00 2015
original 619094989943902209 data Thu Jul 09 07:45:22 GMT-03:00 2015
original 619094910516400129 data Thu Jul 09 07:45:03 GMT-03:00 2015
original 619094893441363969 data Thu Jul 09 07:44:59 GMT-03:00 2015
original 619035151578722304 data Thu Jul 09 03:47:35 GMT-03:00 2015
#abhisek_taneja Games r played in Himachal Pradesh every year if u go
through the schedule of #IPL & #CLT20 properly
original 618914815730290688 data Wed Jul 08 19:49:25 GMT-03:00 2015
original 618908444939186177 data Wed Jul 08 19:24:06 GMT-03:00 2015
original 618862474687705088 data Wed Jul 08 16:21:26 GMT-03:00 2015
We as #T20 follower , #clt20 should be oganized #CLT20
15 cont = 6
Thanks a lot!!
If you set an until date kepp in mind this from the documentation
Returns tweets generated before the given date. Date should be
formatted as YYYY-MM-DD. Keep in mind that the search index may not go
back as far as the date you specify here.
And this too
Before getting involved, it’s important to know that the Search API is
focused on relevance and not completeness. This means that some Tweets
and users may be missing from search results. If you want to match for
completeness you should consider using a Streaming API instead.
So, if you set an until date too old you could get zero tweets, in the other hand if you set a since date too old you could get only tweets from the few past days as you get in the console.

Can't get pubDate to output in Yahoo! Pipes?

In one of my RSS feeds in Yahoo! Pipes, I'm formatting dates using the Date Formatter module and using the format %K so they are pubDate-compliant. In Pipe Output, my four dates appears as follows: Wed, 25 Jul 2012 03:30:00 +0000, Mon, 16 Jul 2012 06:30:00 +0000, Wed, 11 Jul 2012 07:00:00 +0000, and Wed, 27 Jun 2012 13:00:00 +0000.
However, in the RSS feed output, none of these dates appear. Are they formatted incorrectly? Why does Yahoo! Pipes not output these dates?
Okay, so I now realize that I need to output dates to y:published rather than pubDate. This doesn't seem to be widely documented. Even Googling y:published doesn't return many results.
Here are the more detailed steps:
You have an easy-to-read date such as 8 Jan 2013 in its own field, such as pubDate (name doesn't matter; it's just used in Step 2).
Connect your feed to a Loop module. Inside that module, put the Date Builder module, and specify the field where the date is found (such as pubDate).
Still in the Loop module, select "assign results to" and enter item.y:published.
That should output the date in the RSS output in the pubDate field, and it should therefore be readable in any RSS reader.