Exemple #1
0
    def compute_stats(self):
        cmc = self.cmc
        srs = self.srs

        self.price = cmc._p(0)
        self.subs = srs._r(0)

        # cmc
        self.price28 = self.price - cmc._p(28)
        self.price28_rel = div0(self.price, cmc._p(28))

        # reddit
        self.subs28 = self.subs - srs._r(28)
        self.subs7 = self.subs - srs._r(7)
        self.subs1 = self.subs - srs._r(1)

        self.subs28_rel = div0(self.subs, srs._r(28))
        self.subs7_rel = div0(self.subs, srs._r(7))
        self.subs1_rel = div0(self.subs, srs._r(1))

        self.subs7_acc = div0((self.subs7_rel * 4 - 3), self.subs28_rel)
        self.subs1_acc = div0((self.subs1_rel * 7 - 6), self.subs7_rel)

        # compare
        self.cmp28 = div0(self.subs28_rel**2, self.price28_rel)
        self.cmp7 = div0(self.subs7_rel**2, (3 + self.price28_rel) / 4)
        self.cmp1 = div0(self.subs1_rel**2, (27 + self.price28_rel) / 28)

        # score
        self.score = self.cmp28 * (self.subs1_acc**4) * (self.subs7_acc**2)
Exemple #2
0
def _msgs_with_rel(df, gids, miss_pct, sect='bot', lbl='spam'):
    n = len(df[(df[gids] != -1).any(axis=1)])
    frac = ut.div0(n, len(df))
    # sect_pct = 1 - miss_pct if sect == 'top' else miss_pct
    # t = (sect, sect_pct * 100, lbl, frac * 100)
    # ut.out('%s %.2f%% %s w/ relations: %.2f%%' % t)
    return n, frac
Exemple #3
0
    def fetch_prices(self):
        t = 6 * 3600 * int(time.time() / (6 * 3600)) + 6 * 3600
        js = Fetcher(json.loads).fetch(
            URL_PRICES.format(self.id, DATE_START.strftime("%Y-%m-%d"), t))

        self.rawdata = js['data']

        self.btc_series = [(datetime.strptime(k.split("T")[0],
                                              "%Y-%m-%d"), v['BTC'][0])
                           for k, v in self.rawdata.items()]
        if self.data:
            self.btc_series.append(
                (datetime.now(), self.data["quote"]["BTC"]["price"]))
        series_fill_zeroes(self.btc_series)
        normalize(self, "btc_series")

        self.usd_series = [(datetime.strptime(k.split("T")[0],
                                              "%Y-%m-%d"), v['USD'][0])
                           for k, v in self.rawdata.items()]
        if self.data:
            self.usd_series.append(
                (datetime.now(), self.data["quote"]["USD"]["price"]))
        series_fill_zeroes(self.usd_series)
        normalize(self, "usd_series")

        self.supply = []
        try:
            self.supply = [(datetime.strptime(k.split("T")[0], "%Y-%m-%d"),
                            10 * round(0.1 * div0(v['USD'][2], v['USD'][0])))
                           for k, v in self.rawdata.items()]
        except:
            pass
        series_fill_zeroes(self.supply)
        normalize(self, "supply")
Exemple #4
0
def _rm_in_sect(df, tgt_df, cmp_df, gids, miss_pct, num_rel_msgs,
                sect='bot', lbl='spam', boundary='outside'):
    fraction = set()
    tgt_msgs = set(tgt_df['com_id'])
    cmp_msgs = set(cmp_df['com_id'])

    for gid in gids:
        tgt_gids = {x for x in tgt_df[gid] if x != -1}

        for temp_gid, qf in df.groupby(gid):
            if temp_gid in tgt_gids:
                grp_msgs = set(qf['com_id'])
                other = grp_msgs.intersection(cmp_msgs)
                if len(other) > 0:
                    fraction.update(grp_msgs.intersection(tgt_msgs))

    n = ut.div0(len(fraction), num_rel_msgs)
    # sect_pct = 1 - miss_pct if sect == 'top' else miss_pct
    # t = (sect, sect_pct * 100, lbl, boundary, sect, n * 100)
    # self.util_obj.out('%s %.2f%% %s w/ rels %s %s: %.2f%%' % t)
    return n
Exemple #5
0
 def update(self):
     cmc = self.cmc
     D = {
         'day':
         datetime.now().strftime("%Y-%m-%d"),
         'btc':
         self.data["quote"]["BTC"]["price"],
         'usd':
         self.data["quote"]["USD"]["price"],
         'supply':
         div0(self.data["quote"]["USD"]["market_cap"],
              self.data["quote"]["USD"]["price"],
              z=lambda x: 0),
     }
     headers = {'user-agent': 'flowcoin/kriptomist ({})'.format(self.name)}
     if cmc.sub:
         rd = {}
         try:
             rd = session.get(URL_SUBS.format(cmc.sub),
                              headers=headers).json()
         except:
             log.exception("cmc.sub")
         if rd:
             try:
                 D.update(subs=rd["data"]["subscribers"])
             except:
                 log.exception("subs")
             try:
                 D.update(asubs=rd["data"]["active_user_count"])
             except:
                 log.exception("asubs")
     if cmc.twt:
         try:
             D.update(
                 flw=session.get(URL_FLW.format(cmc.twt), headers=headers
                                 ).json()[0]["followers_count"])
         except:
             log.exception("cmc.twt")
     self.db.write_data(D)
Exemple #6
0
    def init(self):
        d = Fetcher(_get_data_from_coinpage).fetch(
            URL_COINPAGE.format(self.coin))

        self.id = list(d['props']['initialState']['cryptocurrency']['info']
                       ['data'].keys())[0]
        self.info = d['props']['initialState']['cryptocurrency']['info'][
            'data'][self.id]
        if self.rank is None:
            self.rank = d['props']['initialState']['cryptocurrency'][
                'quotesLatest']['data'][self.id]['cmc_rank']

        self.max_supply = self.data.get("max_supply", 0)
        if not self.max_supply:
            self.max_supply = self.data.get("total_supply", 0)
        if not self.max_supply:
            self.max_supply = 0
        self.circ_supply = self.data.get("circulating_supply", 0)
        if not self.circ_supply:
            self.circ_supply = 0

        self.supply_rel = 0
        if self.circ_supply and self.max_supply:
            self.supply_rel = div0(self.circ_supply,
                                   self.max_supply,
                                   z=lambda x: 0)

        self.sub = None
        try:
            self.sub = self.info['urls']['reddit'][0].split("/")[-1]
        except:
            log.debug("sub = None")

        self.twt = None
        try:
            self.twt = self.info['urls']['twitter'][0].split("/")[-1]
        except:
            log.debug("twt = None")
Exemple #7
0
    def compute_stats(self):
        p = [a[1] for a in self.coin.btc]
        if self.coin.name == 'bitcoin':
            p = [a[1] for a in self.coin.usd]
        subs = [a[1] for a in self.coin.subs]
        flw = [a[1] for a in self.coin.flw]

        # cmc
        self.price28 = p[-1] - p[-29]
        self.price28_rel = div0(p[-1], p[-29], z=lambda x: 1000)

        # reddit
        self.subs28 = subs[-1] - subs[-29]
        self.subs7 = subs[-1] - subs[-8]
        self.subs1 = subs[-1] - subs[-2]

        self.subs28_rel = div0(subs[-1], subs[-29])
        self.subs7_rel = div0(subs[-1], subs[-8])
        self.subs1_rel = div0(subs[-1], subs[-2])

        self.subs7_acc = div0((self.subs7_rel * 4 - 3), self.subs28_rel)
        self.subs1_acc = div0((self.subs1_rel * 7 - 6), self.subs7_rel)

        # reddit compare
        self.cmp28 = div0(self.subs28_rel**2, self.price28_rel)
        self.cmp7 = div0(self.subs7_rel**2, (3 + self.price28_rel) / 4)
        self.cmp1 = div0(self.subs1_rel**2, (27 + self.price28_rel) / 28)

        # reddit score
        self.score = self.cmp28 * (self.subs1_acc**4) * (self.subs7_acc**2)

        # twitter
        self.flw28 = flw[-1] - flw[-29]
        self.flw7 = flw[-1] - flw[-8]
        self.flw1 = flw[-1] - flw[-2]

        self.flw28_rel = div0(flw[-1], flw[-29])
        self.flw7_rel = div0(flw[-1], flw[-8])
        self.flw1_rel = div0(flw[-1], flw[-2])

        self.flw7_acc = div0((self.flw7_rel * 4 - 3), self.flw28_rel)
        self.flw1_acc = div0((self.flw1_rel * 7 - 6), self.flw7_rel)

        # twitter compare
        self.tcmp28 = div0(self.flw28_rel**2, self.price28_rel)
        self.tcmp7 = div0(self.flw7_rel**2, (3 + self.price28_rel) / 4)
        self.tcmp1 = div0(self.flw1_rel**2, (27 + self.price28_rel) / 28)

        # twitter score
        self.tscore = self.tcmp28 * (self.flw1_acc**4) * (self.flw7_acc**2)