Example #1
0
    def leaderboards(
        self, submissionId=None, clientId=None, competitionId=None, type=None
    ):
        """Query Crowdsource server for leaderboard info
        Keyword Arguments:
          submissionId {[int/str]} -- list of submission ids to filter on
          clientId {[int/str]} -- list of client ids to filter on
          competitionId {[int/str]} -- list of competition ids to filter on
          type {[int/str]} -- list of competition types to filter on

        Returns:
          list of submissions satisfying the above filtering
        """
        self.register()

        send = {}
        if submissionId:
            send["submission_id"] = submissionId
        if clientId:
            send["client_id"] = clientId
        if competitionId:
            send["competition_id"] = competitionId
        if type:
            send["type"] = type
        ret = safe_get(
            construct_path(self._host, "api/v1/submission"),
            data=ujson.dumps(send),
            cookies=self._cookies,
            proxies=self._proxies,
        )
        return ret  # TODO parse into the correct type
Example #2
0
    def competitions(self, clientId=None, competitionId=None, type=None):
        """Query Crowdsource server for competition info
        Keyword Arguments:
          clientId {[int/str]} -- list of client ids to filter on
          competitionId {[int/str]} -- list of competition ids to filter on
          type {[int/str]} -- list of competition types to filter on

        Returns:
          list of competitions satisfying the above filtering
        """
        self.register()

        send = {}
        if competitionId:
            send["competition_id"] = competitionId
        if clientId:
            send["client_id"] = clientId
        if type:
            send["type"] = type

        ret = safe_get(
            construct_path(self._host, "api/v1/competition"),
            data=ujson.dumps(send),
            cookies=self._cookies,
            proxies=self._proxies,
        )

        ret = [
            {
                "competition_id": x["competition_id"],
                "spec": CompetitionSpec.from_dict(x),
            }
            for x in ret
        ]
        return ret
Example #3
0
 def users(self):
     """Return a list of active user ids"""
     self.register()
     return safe_get(
         construct_path(self._host, "api/v1/register"),
         cookies=self._cookies,
         proxies=self._proxies,
     )
Example #4
0
 def register(self):
     """Register client with the competitions host"""
     if not self._am_registered:
         resp, cookies = safe_post_cookies(
             construct_path(self._host, "api/v1/login"),
             data={"key": self._key, "secret": self._secret},
             cookies=self._cookies,
             proxies=self._proxies,
         )
     self._cookies = cookies
Example #5
0
    def start_competition(self, competition):
        """Host a competition

        Arguments:
            competition {CompetitionStruct} -- A competition struct
        """
        if not isinstance(competition, CompetitionSpec):
            raise MalformedCompetitionSpec()

        self.register()
        resp, _ = safe_post_cookies(
            construct_path(self._host, "api/v1/competition"),
            data=ujson.dumps({"spec": competition.to_dict()}),
            cookies=self._cookies,
            proxies=self._proxies,
        )
        self._my_competitions.append(resp)
Example #6
0
 def submit(self, competitionId, submission, submission_format=DatasetFormat.JSON):
     """Submit answers to a competition"""
     self.register()
     if isinstance(submission, pd.DataFrame):
         submission = submission.to_json()
         submission_format = DatasetFormat.JSON
     if not isinstance(submission, SubmissionSpec):
         submission = SubmissionSpec(competitionId, submission, submission_format)
     resp, _ = safe_post_cookies(
         construct_path(self._host, "api/v1/submission"),
         data=ujson.dumps(
             {"competition_id": competitionId, "submission": submission.to_dict()}
         ),
         cookies=self._cookies,
         proxies=self._proxies,
     )
     return resp
Example #7
0
def classify1(host, cookies=None, proxies=None):
    dataset = make_classification()
    competition = CompetitionSpec(
        title="Classify this dataset",
        type=CompetitionType.CLASSIFY,
        expiration=datetime.now() + timedelta(minutes=1),
        prize=1.0,
        dataset=pandas.DataFrame(dataset[0]),
        metric=CompetitionMetric.LOGLOSS,
        answer=pandas.DataFrame(dataset[1]),
    )
    resp = safe_post(
        construct_path(host, "api/v1/competition"),
        data=ujson.dumps({"spec": competition.to_dict()}),
        cookies=cookies,
        proxies=proxies,
    )
    return resp
Example #8
0
def predictCorporateBonds(host, cookies=None, proxies=None):
    competition = CompetitionSpec(
        title="Predict corporate bond volume",
        type=CompetitionType.PREDICT,
        expiration=datetime.now() + timedelta(minutes=1),
        prize=1.0,
        dataset="http://bonds.paine.nyc",
        dataset_type=DatasetFormat.JSON,
        metric=CompetitionMetric.ABSDIFF,
        dataset_key="Name",
        targets={"ABC Corp": ["Price"]},
    )
    resp = safe_post(
        construct_path(host, "api/v1/competition"),
        data=ujson.dumps({"spec": competition.to_dict()}),
        cookies=cookies,
        proxies=proxies,
    )
    return resp
Example #9
0
def predict2(host, cookies=None, proxies=None):
    dataset = cfdg.lines()
    competition = CompetitionSpec(
        title="Predict future value",
        type=CompetitionType.PREDICT,
        expiration=datetime.now() + timedelta(minutes=1),
        prize=1.0,
        dataset=dataset.iloc[:-1],
        metric=CompetitionMetric.ABSDIFF,
        answer=dataset.iloc[-1:],
        targets=dataset.columns,
        when=datetime.utcfromtimestamp(
            dataset[-1:].index.values[0].astype(datetime) / 1000000000),
    )
    resp = safe_post(
        construct_path(host, "api/v1/competition"),
        data=ujson.dumps({"spec": competition.to_dict()}),
        cookies=cookies,
        proxies=proxies,
    )
    return resp
Example #10
0
def predictCitibike(host, cookies=None, proxies=None):
    exp = datetime.now() + timedelta(minutes=2)
    competition = CompetitionSpec(
        title="Predict citibike volume",
        type=CompetitionType.PREDICT,
        when=exp,
        prize=1.0,
        dataset="https://feeds.citibikenyc.com/stations/stations.json",
        dataset_type=DatasetFormat.JSON,
        dataset_key="id",
        dataset_kwargs={"record_column": "stationBeanList"},
        metric=CompetitionMetric.ABSDIFF,
        targets=["availableBikes", "availableDocks"],
        expiration=exp,
    )
    resp = safe_post(
        construct_path(host, "api/v1/competition"),
        data=ujson.dumps({"spec": competition.to_dict()}),
        cookies=cookies,
        proxies=proxies,
    )
    return resp
 def test_constructPath(self):
     assert construct_path("test", "test") == "test"