[Scipy-svn] r2387 - trunk/Lib/sandbox/timeseries

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Dec 11 10:13:48 EST 2006


Author: mattknox_ca
Date: 2006-12-11 09:13:45 -0600 (Mon, 11 Dec 2006)
New Revision: 2387

Modified:
   trunk/Lib/sandbox/timeseries/cseries.c
Log:
removed useless parameter in function, split apart convert function into 2 separate functions

Modified: trunk/Lib/sandbox/timeseries/cseries.c
===================================================================
--- trunk/Lib/sandbox/timeseries/cseries.c	2006-12-11 15:03:34 UTC (rev 2386)
+++ trunk/Lib/sandbox/timeseries/cseries.c	2006-12-11 15:13:45 UTC (rev 2387)
@@ -36,24 +36,18 @@
 	}
 }
 
-
-//fromDate is periods since Dec 31, 1849
 static long
-convert(long fromDate, char fromFreq, char toFreq, int notStartInd, int atEnd)
+toDaily(long fromDate, char fromFreq)
 {
-    long absdate, origin, secondorigin, secsInDay;
-    long converted;
-    int rem;
-    int y,m,d,s;
+    long absdate, origin, secondorigin;
+    int y,m,d;
 
 	mxDateTimeObject *theDate;
-	mxDateTimeObject *convDate;
 
     origin = 675333;
     secondorigin = 722814;
-    secsInDay = 86400;
 
-	//convert fromDate to days since Dec 31, 1849 (Jan 1, 1850 would have absdate of 1)
+	//convert fromDate to days since (0 AD - 1 day)
     switch(fromFreq)
     {
         case 'D':
@@ -65,7 +59,7 @@
         case 'M':
 			y = fromDate/12 + 1;
 			m = fromDate%12;
-			if (atEnd) m++;
+
 			if (m == 0)
 			{
 				m = 12;
@@ -75,9 +69,8 @@
 			break;
         case 'Q':
         	y = fromDate/4 + 1;
-        	m = (fromDate%4) * 3;
-			if (!atEnd) m -= 2;	//change to first month of quarter
-			else m += 1;
+        	m = (fromDate%4) * 3 - 2;
+
 			if (m < 1)
 			{
 				m += 12;
@@ -92,7 +85,6 @@
 			break;
         case 'A':
         	y = fromDate-1;
-        	if (atEnd == 1) y++;
         	m = 1;
         	d = 1;
         	break;
@@ -107,7 +99,6 @@
 
 		theDate = (mxDateTimeObject *)mxDateTime.DateTime_FromDateAndTime(y,m,d,0,0,0);
 		absdate = (long)(theDate->absdate);
-		if (atEnd == 1) absdate--;
 	}
 	else
 	{
@@ -115,11 +106,30 @@
 		absdate += origin;
 	}
 
-	if (atEnd) s = secsInDay-1;
-	else s = 0;
+	return absdate;
 
-	convDate = (mxDateTimeObject *)mxDateTime.DateTime_FromAbsDateAndTime(absdate,s);
+}
 
+
+//fromDate is periods since Dec 31, 1849
+static long
+convert(long fromDate, char fromFreq, char toFreq, int notStartInd)
+{
+    long absdate, origin, secondorigin, secsInDay;
+    long converted;
+    int rem;
+    int y,m,d;
+
+	mxDateTimeObject *convDate;
+
+    origin = 675333;
+    secondorigin = 722814;
+    secsInDay = 86400;
+
+	absdate = toDaily(fromDate, fromFreq);
+
+	convDate = (mxDateTimeObject *)mxDateTime.DateTime_FromAbsDateAndTime(absdate,0);
+
 	//switch back to days and years since 1849 for pyTSA Date
 	absdate -= origin;
 	y = convDate->year - 1849;
@@ -339,7 +349,7 @@
 
     PyObject *returnVal = NULL;
 
-    int notStartInd, atEnd;
+    int notStartInd;
     long startIndex, newStart;
     long i, curPerInd, nextPerInd, prevIndex, curIndex;
     long dim;
@@ -386,20 +396,18 @@
 
 	//convert start index to new frequency
 	notStartInd = 0;
-	atEnd = 0;
-    newStart = convert(startIndex, fromFreq[0], toFreq[0], notStartInd, atEnd);
+    newStart = convert(startIndex, fromFreq[0], toFreq[0], notStartInd);
 
 	//initialize prevIndex
 	prevIndex = newStart - 1;
 
 	notStartInd = 1;
-	atEnd = 0;
 
 	//set values in the new array
     for (i = 0; i < array->dimensions[0]; i++)
     {
 		//find index for start of current period in new frequency
-        curPerInd = convert(startIndex + i, fromFreq[0], toFreq[0], notStartInd, atEnd);
+        curPerInd = convert(startIndex + i, fromFreq[0], toFreq[0], notStartInd);
 
 		//get frequency numeric mapping
 		fromFrVal = freqVal(fromFreq[0]);
@@ -421,7 +429,7 @@
 			newValMask = valMask;
 
 			//find index for start of next period in new frequency
-			nextPerInd = convert(startIndex + i + 1, fromFreq[0], toFreq[0], notStartInd, atEnd);
+			nextPerInd = convert(startIndex + i + 1, fromFreq[0], toFreq[0], notStartInd);
 
 			//adjust for observed setting
 			if (observed[0] == 'S' && PyArray_ISFLOAT(array) && !( (fromFrVal == 4 && toFrVal == 5) || (fromFrVal == 5 && toFrVal == 4) ) )
@@ -509,15 +517,14 @@
     long fromDate;
     char* fromFreq;
     char* toFreq;
-    int notStartInd, atEnd;
+    int notStartInd;
 
     if (!PyArg_ParseTuple(args, "lss:convert(fromDate, fromfreq, tofreq)", &fromDate, &fromFreq, &toFreq)) return NULL;
 
 	//always want start of period (only matters when converting from lower freq to higher freq ie. m -> d)
-	atEnd = 0;
 	notStartInd = 0;
 
-    return PyInt_FromLong(convert(fromDate, fromFreq[0], toFreq[0], notStartInd, atEnd));
+    return PyInt_FromLong(convert(fromDate, fromFreq[0], toFreq[0], notStartInd));
 }
 
 




More information about the Scipy-svn mailing list