← Back to team overview

dhis2-users team mailing list archive

Re: Quick way to add missing ISO weeks going back to 2011?

 

On 5 August 2014 12:04, Bob Jolliffe <bobjolliffe@xxxxxxxxx> wrote:

> No nothing better but could rattle something off - in something slightly
> less exotic than R :-)
>
> Two questions mind you (more for developers):
> 1.  I see we have a period_periodid_seq which doesn't seem to be used.  I
> wonder is this a relic which needs to be removed?  Or does it have some
> other use?
> 2.  Its very easy to create duplicate periods which is not nice.  Probably
> we should consider placing a uniqueness constraint on periodtype+startdate
>

To answer my own question, different versions of dhis have treated these
issues differently. So you'd want to be a little careful depending on the
dhis version used.


>
>
> On 5 August 2014 11:49, Jason Pickering <jason.p.pickering@xxxxxxxxx>
> wrote:
>
>> Hi Randy,
>> I see Bob just replied but was about to send this and will go ahead, but
>> would wait for a more authoritative answer.
>>
>> Here is an R script  which I have used in the past. It is very basic and
>> does not take into account weeks which might already exist. It simply
>> creates a lot of INSERT statements. You will get errors for those which
>> already exist. It would be fairly easy to do this, but would require having
>> R connected to your postgres database to filter out periods which already
>> exist.
>>
>> Use at your own peril and hopefully Bob has something better.
>>
>> Regards,
>> Jason
>>
>> #require(ISOweek)
>> #Adjust to your needs
>> week.starts<-seq(ISOdate(2011,1,3), ISOdate(2014,8,3), by = "1 week")
>> #Number of seconds in a week
>> week.ends<-week.starts + 518399
>> #Get the week names in case you need it
>> #week.names<-gsub("-","",substring(date2ISOweek(week.starts),0,8))
>>
>> sql<-paste0("INSERT INTO periods
>> (periodid,periodtypeid,startdate,enddate)
>> VALUES(nextval('hibernate_sequence'::regclass),2,","'",as.Date(week.starts),"','",as.Date(week.ends),"');")
>> cat(sql,file="insert_periods.sql)
>>
>>
>> On Tue, Aug 5, 2014 at 12:23 PM, Bob Jolliffe <bobjolliffe@xxxxxxxxx>
>> wrote:
>>
>>> Randy do you need a script to generate these?
>>>
>>>
>>> On 4 August 2014 17:11, Wilson, Randy <rwilson@xxxxxxx> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I thought I saw a posting on inserting periods into the DHIS-2 for
>>>> earlier periods in time, but can't seem to find it any longer.
>>>>
>>>> I need ISO weekly periods going back to 2011. I also notice that there
>>>> are some instances where there are 53 ISO weeks in a year, but that does
>>>> not appear to be an option in DHIS-2.
>>>>
>>>> Can someone advise?
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>>
>>>> *Randy Wilson*
>>>>
>>>>
>>>>
>>>> *This message and its attachments are confidential and solely for the
>>>> intended recipients. If received in error, please delete them and notify
>>>> the sender via reply e-mail immediately.*
>>>>  _______________________________________________
>>>> Mailing list: https://launchpad.net/~dhis2-users
>>>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
>>>> Unsubscribe : https://launchpad.net/~dhis2-users
>>>> More help   : https://help.launchpad.net/ListHelp
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~dhis2-users
>>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~dhis2-users
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>>
>>
>

Follow ups

References