Пример #1
0
    def parseTrades(self, data):
        try:
            soup = BeautifulSoup(data, "lxml")
            bodies = soup.find("table").find_all("tbody")

            # read all tds in table sequentaly and store them to array
            tmp = []
            for body in bodies:
                a = body.find_all("td")
                tmp.extend([a[i].text.replace(u'\xa0', ' ') for i in range(len(a))])

            # cut the 7items from a. This will change alignment of trades array.
            # alignment is paired to either: ExitShort-EntryLong / ExitLong-EntryShort
            # tw_trade_id, profit, contracts are just zeroes as those values are useless now
            tmp1 = []
            tmp = tmp[7:]
            while True:
                try:
                    if(len(tmp) < 11):
                        break
                    elif tmp[1] == 'Open':
                        break
                    a = ['0'] + tmp[0:4] + ['0', '0'] + tmp[5:9]
                    tmp1.append(a)
                    tmp = tmp[11:]
                except Exception:
                    break

            # now sort trades by open_time, ascending
            th = TimeHelper()
            return th.sortArrayByDateEx(tmp1, 3)

        except Exception as e:
            print(e.message)
            return None
    def test_GetTimeSinceLastUpdate(self):

        dummyTimeStr = "20171018-23:15:30 UTC"
        dummyTime = TimeHelper.ParseUTCString(dummyTimeStr)
        instanceMeta = InstanceMetadata(id=1,
                                        aws_id=2,
                                        ncommands=10,
                                        nuploads=10,
                                        ndownloads=10,
                                        lastmessage="message",
                                        lastupdate=dummyTimeStr,
                                        ncommandsFinished=0,
                                        nuploadsFinished=0,
                                        ndownloadsFinished=0)

        expectedInterval = TimeHelper.GetTimeElapsed(dummyTimeStr)
        interval = instanceMeta.GetTimeSinceLastUpdate()

        self.assertLess(abs(expectedInterval - interval), 0.1)
    def test_Initialize(self):
        m = Mock(spec=Manifest)
        m.GetJob.side_effect = lambda id: {
            "Id":
            1,
            "RequiredS3Data": ["document", "document1", "document3"],
            "Commands": [{
                "Command": "run1.exe",
                "Args": []
            }, {
                "Command": "run2.exe",
                "Args": ["a"]
            }]
        }
        m.GetS3Documents.side_effect = lambda: [
            {
                "Name": "document",
                "Direction": "Static",
                "LocalPath": ".",
                "AWSInstancePath": "awsinstancepath"
            }, {
                "Name": "document1",
                "Direction": "LocalToAWS",
                "LocalPath": ".",
                "AWSInstancePath": "awsinstancepath"
            }, {
                "Name": "document3",
                "Direction": "AWSToLocal",
                "LocalPath": ".",
                "AWSInstancePath": "awsinstancepath"
            }
        ]

        fac = InstanceMetadataFactory(m)

        instanceMeta = fac.InitializeMetadata(1, 10)
        self.assertEquals(instanceMeta.Get("Id"), 1)
        self.assertEquals(instanceMeta.Get("AWS_Instance_Id"), 10)
        self.assertEquals(instanceMeta.Get("CommandCount"), 2)
        self.assertEquals(instanceMeta.Get("UploadCount"), 1)
        self.assertEquals(instanceMeta.Get("DownloadCount"), 2)
        self.assertEquals(instanceMeta.Get("LastMessage"), "Initialize")
        self.assertTrue(
            TimeHelper.GetTimeElapsed(instanceMeta.Get("LastUpdate")) < 1.0)
        self.assertEquals(instanceMeta.Get("NCommandsFinished"), 0)
        self.assertEquals(instanceMeta.Get("NUploadsFinished"), 0)
        self.assertEquals(instanceMeta.Get("NDownloadsFinished"), 0)

        m.GetJob.assert_called_with(1)
        m.GetS3Documents.assert_any_call()
Пример #4
0
 def InitializeMetadata(self, id, aws_id):
     ncommands = len(self.manifest.GetJob(id)["Commands"])
     nuploads = self._GetUploadCount(id)
     ndownloads = len(self.manifest.GetJob(id)["RequiredS3Data"]) - nuploads
     inst = InstanceMetadata(id=id,
                             aws_id=aws_id,
                             ncommands=ncommands,
                             nuploads=nuploads,
                             ndownloads=ndownloads,
                             lastmessage="Initialize",
                             lastupdate=TimeHelper.GetUTCNowString(),
                             ncommandsFinished=0,
                             nuploadsFinished=0,
                             ndownloadsFinished=0)
     return inst
    def test_IncrementUploadsFinished(self):
        instanceMeta = InstanceMetadata(id=1,
                                        aws_id=2,
                                        ncommands=10,
                                        nuploads=10,
                                        ndownloads=10,
                                        lastmessage="message",
                                        lastupdate="empty",
                                        ncommandsFinished=0,
                                        nuploadsFinished=0,
                                        ndownloadsFinished=0)

        self.assertEqual(instanceMeta.Get("NUploadsFinished"), 0)
        self.assertEqual(instanceMeta.Get("LastUpdate"), "empty")
        instanceMeta.IncrementUploadsFinished()
        self.assertEqual(instanceMeta.Get("NUploadsFinished"), 1)
        newTime = instanceMeta.Get("LastUpdate")
        self.assertTrue(TimeHelper.GetTimeElapsed(newTime) < 1.0)
Пример #6
0
 def GetTimeSinceLastUpdate(self):
     return TimeHelper.GetTimeElapsed(self._doc["LastUpdate"])
Пример #7
0
 def IncrementDownloadFinished(self):
     self._doc["NDownloadsFinished"] += 1
     self._doc["LastMessage"] = "download finished"
     self._doc["LastUpdate"] = TimeHelper.GetUTCNowString()
Пример #8
0
 def IncrementCommandFinished(self):
     self._doc["NCommandsFinished"] += 1
     self._doc["LastMessage"] = "command finished"
     self._doc["LastUpdate"] = TimeHelper.GetUTCNowString()
Пример #9
0
 def UpdateMessage(self, msg):
     self._doc["LastUpdate"] = TimeHelper.GetUTCNowString() 
     self._doc["LastMessage"] = msg