def fromCSVRow(aRow): id = int(aRow.pop(0)) period = Period( TimeFormatter.toDatetime( aRow.pop(0) ), TimeFormatter.toDatetime( aRow.pop(0) )) nickName = aRow.pop(0) savedDateTime = TimeFormatter.toDatetime(aRow.pop(0)) result = Group(id,period.start,period.end,nickName,savedDateTime) return result
def testTypeDeterminationOfPayment(self): apiCall = APICall(anUrl="/foradmin/before_payment", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual( apiCall.type, APICall.TYPE_PAYMENT ) apiCall = APICall(anUrl="/foradmin/before_payment/asd", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual( apiCall.type, None ) apiCall = APICall(anUrl="/foradmin", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual( apiCall.type, None )
def testContradictoryCreation(self): try: Period(TimeFormatter.toDatetime('2014-01-01 00:00:00'), TimeFormatter.toDatetime('2013-12-01 23:59:59')) except: return self.fail()
def testAnalyzeNewGroups(self): cohort = Cohort( aStartDate=TimeFormatter.toDatetime('2014-05-05 00:00:00'), aEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aInterval=7) groups = cohort.groups group = Group( anId=1, aStartDate=TimeFormatter.toDatetime('2014-05-05 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-11 23:59:59'), aNickname="5월 1째 주") self.assertEqual(groups[0].period, group.period) group = Group( anId=2, aStartDate=TimeFormatter.toDatetime('2014-05-12 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-18 23:59:59'), aNickname="5월 2째 주") self.assertEqual(groups[1].period, group.period) group = Group( anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-19 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-25 23:59:59'), aNickname="5월 3째 주") self.assertEqual(groups[2].period, group.period) group = Group( anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-26 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="5월 4째 주") self.assertEqual(groups[3].period, group.period) self.assertEqual(groups.__len__(), 4)
def fromCSVRow(aRow): id = int(aRow.pop(0)) period = Period(TimeFormatter.toDatetime(aRow.pop(0)), TimeFormatter.toDatetime(aRow.pop(0))) nickName = aRow.pop(0) savedDateTime = TimeFormatter.toDatetime(aRow.pop(0)) result = Group(id, period.start, period.end, nickName, savedDateTime) return result
def testUpdate(self): self.saveAll(self.groups) newGroup = Group( anId=1, aStartDate=TimeFormatter.toDatetime('2013-01-01 00:00:00'), anEndDate=TimeFormatter.toDatetime('2015-12-10 23:59:59'), aNickname="2013~2015") newGroup.save()
def testTypeDeterminationOfShallowSearch(self): apiCall = APICall(anUrl="/classes/dance/etc/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, APICall.TYPE_SHALLOW_SEARCH ) apiCall = APICall(anUrl="/classes/music/etc/2", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, APICall.TYPE_SHALLOW_SEARCH ) apiCall = APICall(anUrl="/classes/music", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, None ) apiCall = APICall(anUrl="/classes/kk/ho/123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, None )
def testTypeDeterminationOfDetailView(self): apiCall = APICall(anUrl="/classes/1/3", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, APICall.TYPE_DETAIL_VIEW ) apiCall = APICall(anUrl="/classes/123123/7777", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, APICall.TYPE_DETAIL_VIEW ) apiCall = APICall(anUrl="/classes/123123/7777/123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual( apiCall.type, None ) apiCall = APICall(anUrl="/classes/123123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{r}") self.assertEqual( apiCall.type, None )
def testTypeDeterminationOfFilter(self): apiCall = APICall( anUrl="/classes/dance/etc/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual(apiCall.type, APICall.TYPE_FILTER) apiCall = APICall( anUrl="/classes/music/hoho/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012'}") self.assertEqual(apiCall.type, APICall.TYPE_FILTER)
def testEnableToCapture(self): group = Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-06-01 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="6월 1일") snapshot = Snapshot(group) snapshot.capture(TimeFormatter.toDatetime('2014-06-07 23:59:59')) self.assertTrue( snapshot.funnel is not None) try: snapshot.capture(TimeFormatter.toDatetime('2014-06-01 23:59:59')) except: return self.fail("this is not correct time relation, should be failed")
def testAnalyzeNewGroups(self): cohort = Cohort(aStartDate=TimeFormatter.toDatetime('2014-05-05 00:00:00'), aEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aInterval = 7) groups = cohort.groups group = Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-05-05 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-11 23:59:59'), aNickname="5월 1째 주") self.assertEqual(groups[0].period, group.period) group = Group(anId=2, aStartDate=TimeFormatter.toDatetime('2014-05-12 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-18 23:59:59'), aNickname="5월 2째 주") self.assertEqual(groups[1].period, group.period) group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-19 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-25 23:59:59'), aNickname="5월 3째 주") self.assertEqual(groups[2].period, group.period) group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-26 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="5월 4째 주") self.assertEqual(groups[3].period, group.period) self.assertEqual(groups.__len__(),4)
def testTypeDeterminationOfPayment(self): apiCall = APICall( anUrl="/foradmin/before_payment", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual(apiCall.type, APICall.TYPE_PAYMENT) apiCall = APICall( anUrl="/foradmin/before_payment/asd", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual(apiCall.type, None) apiCall = APICall( anUrl="/foradmin", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual(apiCall.type, None)
def setUp(self): try: os.remove( RelativeProjectPathManager.getRealFilePathToSave( Group.FILE_PATH_TO_SAVE)) except: pass Group.FILE_PATH_TO_SAVE = GroupTest.directoryPathToSave self.groups = [] self.groups.append( Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-06-01 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="5월 4째주")) self.groups.append( Group(anId=2, aStartDate=TimeFormatter.toDatetime('2011-09-09 00:00:00'), anEndDate=TimeFormatter.toDatetime('2013-12-12 23:59:59'), aNickname="ㅋㅋㅋ"))
def testTypeDeterminationOfShallowSearch(self): apiCall = APICall( anUrl="/classes/dance/etc/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, APICall.TYPE_SHALLOW_SEARCH) apiCall = APICall( anUrl="/classes/music/etc/2", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, APICall.TYPE_SHALLOW_SEARCH) apiCall = APICall( anUrl="/classes/music", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, None) apiCall = APICall( anUrl="/classes/kk/ho/123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, None)
def testTypeDeterminationOfDetailView(self): apiCall = APICall( anUrl="/classes/1/3", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, APICall.TYPE_DETAIL_VIEW) apiCall = APICall( anUrl="/classes/123123/7777", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, APICall.TYPE_DETAIL_VIEW) apiCall = APICall( anUrl="/classes/123123/7777/123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{}") self.assertEqual(apiCall.type, None) apiCall = APICall( anUrl="/classes/123123", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{r}") self.assertEqual(apiCall.type, None)
def fromJson(aJsonString): jsonDict= json.loads(aJsonString) return APICall(anUrl=jsonDict[APICall.JSON_PARM_URL], aCreatedDateTime=TimeFormatter.toDatetime(jsonDict[APICall.JSON_PARM_CREATED_DATE_TIME]), aParm=jsonDict[APICall.JSON_PARM_PARM].__str__())
# funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-05-20 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-19 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-25 23:59:59'), aNickname="5월 3째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-05-27 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-26 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="5월 4째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-06-03 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-06-02 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-08 23:59:59'), aNickname="6월 1째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-06-10 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-06-09 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-14 23:59:59'), aNickname="5월 4째 주") snapshot = Snapshot(group) funnel = snapshot.capture(TimeFormatter.toDatetime('2014-06-16 00:00:00')) print( str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()))
from src.main.domain.Group import Group from src.main.domain.Snapshot import Snapshot from src.main.domain.UserBehavior import UserBehavior from src.main.util.TimeFormatter import TimeFormatter __author__ = 'continueing' if __name__ == "__main__": group = Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-06-15 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-19 23:59:59'), aNickname="6월 12일 하루") group.save() snapshot = Snapshot(group) snapshot.capture(TimeFormatter.toDatetime( '2014-06-20 00:00:00') ) funnel = snapshot.funnel print('Indifference:\t\t' + str(funnel.countNumberOfIndifference())) print('curios:\t\t' + str(funnel.countNumberOfCurios())) print('interested:\t\t' + str(funnel.countNumberOfInterested())) print('filter:\t\t' + str(funnel.countNumberOfFilter())) print('payment:\t\t' + str(funnel.countNumberOfPayment())) userbehavior = UserBehavior.instantiateBasedOnSessionIdWithCaptureDatetime("09FN8+0qQscHPgeR5RrTmg==",TimeFormatter.toDatetime( '2014-06-20 00:00:00')) userbehavior.printLog()
from src.main.domain.Group import Group from src.main.domain.Snapshot import Snapshot from src.main.domain.UserBehavior import UserBehavior from src.main.util.TimeFormatter import TimeFormatter __author__ = 'continueing' if __name__ == "__main__": group = Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-06-15 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-19 23:59:59'), aNickname="6월 12일 하루") group.save() snapshot = Snapshot(group) snapshot.capture(TimeFormatter.toDatetime('2014-06-20 00:00:00')) funnel = snapshot.funnel print('Indifference:\t\t' + str(funnel.countNumberOfIndifference())) print('curios:\t\t' + str(funnel.countNumberOfCurios())) print('interested:\t\t' + str(funnel.countNumberOfInterested())) print('filter:\t\t' + str(funnel.countNumberOfFilter())) print('payment:\t\t' + str(funnel.countNumberOfPayment())) userbehavior = UserBehavior.instantiateBasedOnSessionIdWithCaptureDatetime( "09FN8+0qQscHPgeR5RrTmg==", TimeFormatter.toDatetime('2014-06-20 00:00:00')) userbehavior.printLog()
print("indifference, curious, interested, filter, payment") # group = Group(anId=1, aStartDate=TimeFormatter.toDatetime('2014-05-05 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-11 23:59:59'), aNickname="5월 1째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-05-13 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.printCuriosUserSessions()) + ', ' + str(funnel.printInterestedUserSessions()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # group = Group(anId=2, aStartDate=TimeFormatter.toDatetime('2014-05-12 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-18 23:59:59'), aNickname="5월 2째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-05-20 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-19 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-05-25 23:59:59'), aNickname="5월 3째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-05-27 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-05-26 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-01 23:59:59'), aNickname="5월 4째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-06-03 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) # # group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-06-02 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-08 23:59:59'), aNickname="6월 1째 주") # snapshot = Snapshot(group) # funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-06-10 00:00:00') ) # print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) ) group = Group(anId=3, aStartDate=TimeFormatter.toDatetime('2014-06-09 00:00:00'), anEndDate=TimeFormatter.toDatetime('2014-06-14 23:59:59'), aNickname="5월 4째 주") snapshot = Snapshot(group) funnel = snapshot.capture(TimeFormatter.toDatetime( '2014-06-16 00:00:00') ) print(str(funnel.countNumberOfIndifference()) + ', ' + str(funnel.countNumberOfCurios()) + ', ' + str(funnel.countNumberOfInterested()) + ', ' + str(funnel.countNumberOfFilter()) + ', ' + str(funnel.countNumberOfPayment()) )
def testTypeDeterminationOfFilter(self): apiCall = APICall(anUrl="/classes/dance/etc/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012', 'location':'강남'}") self.assertEqual( apiCall.type, APICall.TYPE_FILTER ) apiCall = APICall(anUrl="/classes/music/hoho/1", aCreatedDateTime=TimeFormatter.toDatetime("2014-02-12 23:11:20"), aParm="{'time':'012'}") self.assertEqual( apiCall.type, APICall.TYPE_FILTER )
def testInstantiateUserBehaviorBySessionId(self): try: userBehavior = UserBehavior.instantiateBasedOnSessionIdWithCaptureDatetime(aSessionId = 'W1A/aq3DnaO6NpBrD8gbzw==', aCaptureDatetime=TimeFormatter.toDatetime('2014-06-01 11:23:30')) except: self.fail("fail to instantiate userBehavior, this function is related with http request and json parsing tasks.")
def fromDict(aJsonDict): return APICall(anUrl=aJsonDict[APICall.JSON_PARM_URL], aCreatedDateTime=TimeFormatter.toDatetime(aJsonDict[APICall.JSON_PARM_CREATED_DATE_TIME]), aParm=aJsonDict[APICall.JSON_PARM_PARM].__str__())
def fromDict(aJsonDict): return APICall(anUrl=aJsonDict[APICall.JSON_PARM_URL], aCreatedDateTime=TimeFormatter.toDatetime( aJsonDict[APICall.JSON_PARM_CREATED_DATE_TIME]), aParm=aJsonDict[APICall.JSON_PARM_PARM].__str__())
def fromJson(aJsonString): jsonDict = json.loads(aJsonString) return APICall(anUrl=jsonDict[APICall.JSON_PARM_URL], aCreatedDateTime=TimeFormatter.toDatetime( jsonDict[APICall.JSON_PARM_CREATED_DATE_TIME]), aParm=jsonDict[APICall.JSON_PARM_PARM].__str__())
def testIsAndroidUser(self): userBehavior = UserBehavior.instantiateBasedOnSessionIdWithCaptureDatetime(aSessionId = 'W1A/aq3DnaO6NpBrD8gbzw==', aCaptureDatetime=TimeFormatter.toDatetime('2014-06-11 11:23:30')) self.assertTrue(userBehavior.isAndroidUser())