<commit_before>#!/bin/python
# -*- coding: utf-8 -*-

import csv
import json
import requests
from ctrls import *
from config import *
from os import listdir
from datetime import date

class Tester():
    '''To Test models'''

    def __init__(self, numbers, Model):
        # check the number from Database, remove error numbers
        tsecNumbers = [ n[:-4] for n in listdir(TSEC_DATA_PATH) if n[-4:] == '.csv' ]
        for number in numbers:
            if number not in tsecNumbers:
                numbers.remove(number)

        self.numbers = numbers
        self.Model = Model

    def _printTrade(self, row, trade):
        print ('%s %s %d at %.2f, Money: %d, Stock: %d, Asset: %d, Rate: %.3f%%' % 
            (row[0], trade['Act'], trade['Volume'], trade['Value'], 
            trade['Money'], trade['Stock'], trade['Asset'], trade['Rate'])
        )

    def _getTmpData(self, number):

        page = requests.get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_'+number+'.tw&json=1&delay=0')
        content = json.loads(page.content)
        vals = content['msgArray'][0]
        t = date.today()
        return [str(t.year-1911)+'/'+str(t.month).zfill(2)+'/'+str(t.day).zfill(2),
                vals['v'], 0, vals['o'], vals['h'], vals['l'], vals['z'], 0, 0]

    def _notInPeriod(self, row, dateFrom, dateTo):

        data_day = date(int(row[0].split('/')[0])+1911, 
                        int(row[0].split('/')[1]),
                        int(row[0].split('/')[2]))

        if dateFrom and (data_day - dateFrom).days < 0:
            return True
        elif dateTo and (data_day - dateTo).days > 0:
            return True
        else:
            return False

    def run(self, mode = 'train', noLog = False, noRecord = False, dateFrom = None, dateTo = None, roiThr = -100, drawCandle = True):
        '''<commit_msg>fix Trader bug<commit_after>#!/bin/python
# -*- coding: utf-8 -*-

import csv
import json
import requests
from ctrls import *
from config import *
from os import listdir
from datetime import date

class Tester():
    '''To Test models'''

    def __init__(self, numbers, Model):
        # check the number from Database, remove error numbers
        tsecNumbers = [ n[:-4] for n in listdir(TSEC_DATA_PATH) if n[-4:] == '.csv' ]
        for number in numbers:
            if number not in tsecNumbers:
                numbers.remove(number)

        self.numbers = numbers
        self.Model = Model

    def _printTrade(self, row, trade):
        print ('%s %s %d at %.2f, Money: %d, Stock: %d, Asset: %d, Rate: %.3f%%' % 
            (row[0], trade['Act'], trade['Volume'], round(trade['Value']/1000, 2), 
            trade['Money'], trade['Stock'], trade['Asset'], trade['Rate'])
        )

    def _getTmpData(self, number):

        page = requests.get('http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_'+number+'.tw&json=1&delay=0')
        content = json.loads(page.content)
        vals = content['msgArray'][0]
        t = date.today()
        return [str(t.year-1911)+'/'+str(t.month).zfill(2)+'/'+str(t.day).zfill(2),
                vals['v'], 0, vals['o'], vals['h'], vals['l'], vals['z'], 0, 0]

    def _notInPeriod(self, row, dateFrom, dateTo):

        data_day = date(int(row[0].split('/')[0])+1911, 
                        int(row[0].split('/')[1]),
                        int(row[0].split('/')[2]))

        if dateFrom and (data_day - dateFrom).days < 0:
            return True
        elif dateTo and (data_day - dateTo).days > 0:
            return True
        else:
            return False

    def run(self, mode = 'train', noLog = False, noRecord = False, dateFrom = None, dateTo = None, roiThr = -100, drawCandle = True):
        '''
{'fraction_non_alphanumeric': 0.17086234600964115, 'fraction_numerical': 0.019014461703267274, 'mean_word_length': 2.3318465655664586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1724528', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1198, 'n_words': 311}