Gentoo Archives: gentoo-user

From: Albert Hopkins <marduk@×××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] VERY OFF TOPIC - change sparse data to daily data
Date: Thu, 15 Nov 2007 23:27:23
Message-Id: 1195168822.1972.30.camel@blackwidow.nbk
In Reply to: [gentoo-user] VERY OFF TOPIC - change sparse data to daily data by Mark Knecht
1 On Thu, 2007-11-15 at 14:25 -0800, Mark Knecht wrote:
2 > Hi,
3 > I know this is EXTREMELY off topic but I don't know of another
4 > better list to ask on. I'm hoping maybe there is a Linux command line
5 > method for doing this. Thanks in advance.
6 >
7 > I have a data file with data that changes infrequently. The file
8 > lists only the day the data changes. There are only 144 lines
9 > representing 23 years of data. There are three values for the data -
10 > 1, 0 & -1. The file looks like this:
11 >
12 > 09/27/74, 1
13 > 07/11/75, -1
14 > 08/01/75, 1
15 > 03/12/76, -1
16 > 04/02/76, 1
17 > 05/07/76, -1
18 > 06/04/76, 1
19 >
20 > I need to turn this data into a file with the same format but one
21 > that has data for every date, something like this:
22 >
23 > 09/28/74, 1
24 > 09/29/74, 1
25 > 09/30/74, 1
26 > ...
27 > ...
28 > ...
29 > 07/09/75, 1
30 > 07/10/75, 1
31 > 07/11/75, -1
32 >
33 > and so on...
34 >
35 > Would anyone proficient in Linux command line know how to do that?
36 > Or might there be some app in portage that could do this as part of
37 > it's functionality?
38 >
39
40 You're probably not going to find something so specific "off the
41 shelf" (although if I'm wrong, someone will correct me). Likely you'll
42 have to do some kind of scripting (either in bash or whatever). With
43 that in mind, it would be relatively easy to do in python:
44
45 Read the file and put data into a dict:
46
47 >>> date_dict[datetime.date(1975, 04, 12)] = -1
48 ...
49 Then write a loop
50 >>> start_date = datetime.date(1972, 3, 1)
51 >>> end_date = datetime.date(2007, .....
52 >>> one_day = datetime.datedelta(days=1)
53 >>> default_value = 1
54 >>> mydate = start_date
55 >>> while mydate <= end_date:
56 >>> ... value = date_dict.get(mydate, default_value)
57 >>> ... outfile.write('%s %s\n' % (mydate, value))
58 >>> ... mydate = mydate + one_day
59
60 That's the general idea, though the above code is incomplete and
61 untested.
62
63 BTW, 2-digit year is a bad idea (unless it's truly 74 AD ;-).
64
65 --
66 Albert W. Hopkins
67
68 --
69 gentoo-user@g.o mailing list