Beispiel #1
0
    def test_answerPrototype6(self):
        # AnswerType.SIX
        dataset = cfdg.ohlcv().reset_index()
        exp = datetime.utcfromtimestamp(
            dataset[-1:]['index'].values[0].astype(datetime) / 1000000000)
        competition = CompetitionSpec(title='',
                                      type=CompetitionType.PREDICT,
                                      expiration=datetime.now() +
                                      timedelta(minutes=1),
                                      prize=1.0,
                                      dataset=dataset.iloc[:-1],
                                      metric=CompetitionMetric.ABSDIFF,
                                      targets=dataset.columns[-1],
                                      answer=dataset.iloc[-1:],
                                      dataset_key='index',
                                      when=exp)

        df = answerPrototype(competition)[['when', dataset.columns[-1]]]
        ans = pd.DataFrame([{
            'when': exp,
            dataset.columns[-1]: np.nan
        } for x in dataset['index'].iloc[:-1]],
                           index=[x for x in dataset['index'].iloc[:-1]
                                  ])[['when', dataset.columns[-1]]]
        print(df)
        print(ans)
        assert df.equals(ans)
Beispiel #2
0
    def test_checkAnswer2(self):
        dataset = cfdg.ohlcv()
        competition = CompetitionSpec(
            title='',
            type=CompetitionType.PREDICT,
            expiration=datetime.now() + timedelta(minutes=1),
            prize=1.0,
            dataset=dataset.iloc[:-1],
            metric=CompetitionMetric.ABSDIFF,
            targets=dataset.columns[-1],
            answer=dataset.iloc[-1:],
            when=datetime.utcfromtimestamp(
                dataset[-1:].index.values[0].astype(datetime) / 1000000000))

        c2 = Competition.from_spec(1, competition)
        ans = foo3(competition)
        print(ans)
        d2 = SubmissionSpec.from_dict({
            'competition_id': 2,
            'answer': ans.to_json(),
            'answer_type': DatasetFormat.JSON
        })
        s = Submission.from_spec(1, 2, c2, d2)

        checkAnswer(s)
Beispiel #3
0
    def test_answerPrototype9(self):
        # AnswerType.NINE
        dataset = cfdg.ohlcv()
        competition = CompetitionSpec(
            title="",
            type=CompetitionType.PREDICT,
            expiration=datetime.now() + timedelta(minutes=1),
            prize=1.0,
            dataset=dataset.iloc[:-1],
            metric=CompetitionMetric.ABSDIFF,
            targets=dataset.columns[-1],
            answer=dataset.iloc[-1:],
        )

        df = answerPrototype(competition)
        ans = pd.DataFrame([{dataset.columns[-1]: np.nan} for x in dataset.index])
        ans = pd.DataFrame([{dataset.columns[-1]: np.nan}])
        print(df)
        print(ans)
        assert df.equals(ans)
Beispiel #4
0
    def test_answerPrototype8(self):
        # AnswerType.EIGHT
        dataset = cfdg.ohlcv()
        exp = datetime.utcfromtimestamp(
            dataset[-1:].index.values[0].astype(datetime) / 1000000000)
        competition = CompetitionSpec(title='',
                                      type=CompetitionType.PREDICT,
                                      expiration=datetime.now() +
                                      timedelta(minutes=1),
                                      prize=1.0,
                                      dataset=dataset.iloc[:-1],
                                      metric=CompetitionMetric.ABSDIFF,
                                      targets=dataset.columns[-1],
                                      answer=dataset.iloc[-1:],
                                      when=exp)

        df = answerPrototype(competition)
        ans = pd.DataFrame([{dataset.columns[-1]: np.nan}], index=[exp])
        print(df)
        print(ans)
        assert df.equals(ans)
Beispiel #5
0
def predict1(host, id, cookies=None, proxies=None):
    dataset = cfdg.ohlcv()
    competition = CompetitionSpec(
        title='Predict next day volume',
        type=CompetitionType.PREDICT,
        expiration=datetime.now() + timedelta(minutes=1),
        prize=1.0,
        dataset=dataset.iloc[:-1],
        metric=CompetitionMetric.ABSDIFF,
        targets=dataset.columns[-1],
        answer=dataset.iloc[-1:],
        when=datetime.utcfromtimestamp(
            dataset[-1:].index.values[0].astype(datetime) / 1000000000))
    resp = safe_post(construct_path(host, 'api/v1/competition'),
                     data=ujson.dumps({
                         'id': id,
                         'spec': competition.to_dict()
                     }),
                     cookies=cookies,
                     proxies=proxies)
    return resp
Beispiel #6
0
    def test_answerPrototype7(self):
        # AnswerType.SEVEN
        dataset = cfdg.ohlcv().reset_index()
        competition = CompetitionSpec(title='',
                                      type=CompetitionType.PREDICT,
                                      expiration=datetime.now() +
                                      timedelta(minutes=1),
                                      prize=1.0,
                                      dataset=dataset.iloc[:-1],
                                      metric=CompetitionMetric.ABSDIFF,
                                      targets=dataset.columns[-1],
                                      dataset_key='index',
                                      answer=dataset.iloc[-1:])

        df = answerPrototype(competition)
        ans = pd.DataFrame([{
            dataset.columns[-1]: np.nan
        } for x in dataset['index'].iloc[:-1]],
                           index=dataset['index'].iloc[:-1])
        print(df)
        print(ans)
        assert df.equals(ans)
Beispiel #7
0
def getCFData(type, n_categories=5, n=100, **kwargs):
    if type == 'scatter':
        return scatter(n_categories,
                       n,
                       prefix=kwargs.get('prefix', 'category'),
                       mode=kwargs.get('mode', None))[['x', 'y', 'categories', 'text']]
    elif type == 'scatter3d':
        return scatter3d(n_categories,
                         n,
                         prefix=kwargs.get('prefix', 'category'),
                         mode=kwargs.get('mode', None))
    elif type == 'bubble':
        return bubble(n_categories,
                      n,
                      prefix=kwargs.get('prefix', 'category'),
                      mode=kwargs.get('mode', None))[['x', 'y', 'categories', 'size', 'text']]
    elif type == 'bubble3d':
        return bubble3d(n_categories,
                        n,
                        prefix=kwargs.get('prefix', 'category'),
                        mode=kwargs.get('mode', None))
    elif type == 'pie':
        return pie(n_labels=kwargs.get('n_lablels', 5),
                   mode=kwargs.get('mode', None))
    elif type == 'heatmap':
        return heatmap(n_x=kwargs.get('n_x', 5),
                       n_y=kwargs.get('n_y', 10))
    elif type == 'bars':
        return bars(n,
                    n_categories,
                    prefix=kwargs.get('prefix', 'category'),
                    columns=kwargs.get('columns', None),
                    mode=kwargs.get('mode', 'abc'))
    elif type == 'ohlc':
        return ohlc(n)
    elif type == 'ohlcv':
        return ohlcv(n)
    elif type == 'box':
        return box(n_traces=kwargs.get('n_traces', 5),
                   n=n,
                   mode=kwargs.get('mode', None))
    elif type == 'histogram':
        return histogram(n_traces=kwargs.get('n_traces', 1),
                         n=n,
                         mode=None)
    elif type == 'surface':
        return surface(n_x=kwargs.get('n_x', 20),
                       n_y=kwargs.get('n_y', 20))
    elif type == 'sinwave':
        return sinwave(n=n,
                       inc=kwargs.get('inc', .25))
    if type == 'scattergeo':
        return scattergeo()
    elif type == 'choropleth':
        return choropleth()
    elif type == 'stock':
        return getName(n=1,
                       name=kwargs.get('name', 3),
                       exchange=kwargs.get('exchange', 2),
                       columns=kwargs.get('columns', None),
                       mode=kwargs.get('mode', 'abc'))
    else:
        return lines(n_traces=kwargs.get('n_traces', 5),
                     n=n,
                     columns=kwargs.get('columns', None),
                     dateIndex=kwargs.get('dateIndex', True),
                     mode=kwargs.get('mode', None))