def __init__(self, qid, updid, updtime, updconf, updlen, numngts, ngtstr):
     self.qid = qid
     self.updid = updid
     self.time = float(updtime)
     self.conf = float(updconf)
     self.wlen = int(updlen)
     self.numngts = int(numngts)
     self.nuggets = []
     if ngtstr or self.numngts:
         for ngts in ngtstr.split():
             self.nuggets.append(Nugget(*ngts.split(',')))
    def load_run_and_attach_gain(runfile, updlens, nuggets, matches,
                                 useAverageLengths, track, query_durns):
        """
        This function attaches gain (nuggets) to sentences of a run, on the fly
        """
        run = {}
        with open(runfile) as rf:
            for line in rf:
                if len(line.strip()) == 0: continue
                qid, teamid, runid, docid, sentid, updtime, confidence = line.strip(
                ).split()
                if track == 'ts14':
                    qid = 'TS14.' + qid
                updid = docid + '-' + sentid
                updtime = float(updtime) - query_durns[qid][
                    0]  # timestamps to start from 0
                confidence = float(confidence)
                updlen = 30 if not useAverageLengths else updlens[qid][
                    "topic.avg.update.length"]  #default updlen is 30
                if updid in updlens[qid]:
                    updlen = updlens[qid][updid]
                else:
                    pass
                    #print >> sys.stderr, 'no length for ', updid

                if qid not in run:
                    run[qid] = []

                #gain for update
                ngtstr = ""
                num_ngts = 0
                matching_nuggets = []
                if updid in matches[qid]:  #update is relevant
                    ngts_in_upd = matches[qid][updid]
                    for ngtid in ngts_in_upd:
                        if ngtid not in nuggets[
                                qid]:  # there are 2 nuggets not in nuggets.tsv
                            continue
                        num_ngts += 1
                        ngt_gain, ngt_time = nuggets[qid][ngtid]
                        # ngtstr += ','.join([ str(s) for s in [ngtid, ngt_gain, ngt_time] ])
                        # ngtstr += ' '
                        matching_nuggets.append(
                            Nugget(ngtid, ngt_gain, ngt_time))

                #run[qid].append( [updtime, confidence, updid, updlen, num_ngts, ngtstr] )
                updobj = Update(qid, updid, updtime, confidence, updlen,
                                num_ngts, ngtstr)
                updobj.nuggets = matching_nuggets
                if qid not in run:
                    run[qid] = []
                run[qid].append(updobj)
        return run
Example #3
0
    def generate_nuggets(self):
        n = []

        for i in range(0, self.size[0] * self.size[1]):
            if i % 2 == 0:
                symbol = self.get_rand_symbol()
                color = self.get_rand_color()

            n.append(Nugget(symbol, color))

        random.shuffle(n)

        return n
    def microblog_load_run_and_attach_gain(runfile, nuggets, matches, track,
                                           query_durns):
        run = {}
        qids_matched = defaultdict(int)
        qids_ignored = defaultdict(int)
        with gzip.open(runfile) as rf:
            for line in rf:

                qid, tweet, epoch, runtag = line.strip().split()

                if track == 'mb15':
                    qid = qid.replace("MB", "")

                #print qid, tweet, epoch, runtag

                if qid not in matches:
                    qids_ignored[qid] += 1
                    continue
                qids_matched[qid] += 1

                if qid not in query_durns:
                    logger.error(
                        'qid {} not in query_durns: qid in matches {}'.format(
                            qid, qid in matches))

                epoch = float(epoch) - query_durns[qid][0]

                matching_nuggets = []
                if tweet in matches[qid]:
                    mc = matches[qid][tweet]
                    if qid in nuggets and mc in nuggets[qid]:
                        mcgain, mctime = nuggets[qid][mc]
                        matching_nuggets.append(Nugget(mc, mcgain, mctime))

                updobj = Update(qid, tweet, epoch, 1.0, 140 / 5.1,
                                len(matching_nuggets), "")
                updobj.nuggets = matching_nuggets

                if qid not in run:
                    run[qid] = []
                run[qid].append(updobj)

        # print len(qids_matched),qids_matched
        # print len(qids_ignored),qids_ignored
        return run
Example #5
0
def new(code):
    if request.method == 'GET':
        if not flask_login.current_user.is_authenticated:
            session['url'] = url_for('new', code=code)
            return redirect(url_for('login'))
        return render_template('new.html', code=code)
    else:
        discovered = DiscoveredNugget.objects(code__exact=code).first()
        if discovered == None:
            Flask.abort(401)
        else:
            new_nugget = Nugget()
            new_nugget.message_list = []
            new_nugget.name = request.form['name']
            new_nugget.mac = discovered['mac']
            new_nugget.assigner = request.form['assigner']
            new_nugget.assignee = flask_login.current_user.username
            new_nugget.weather_lat = "0"
            new_nugget.weather_lon = "0"
            new_nugget.display_weather = False
            new_nugget.delay = 5
            new_nugget.cached_weather = None
            new_nugget.save()
            return redirect(url_for('home'))
Example #6
0
def read(path):
    with open(path, 'r') as csvfile:
        file = csv.reader(csvfile, delimiter='\t')
        res = [Nugget(t) for t in file]
        return res
Example #7
0
File: game.py Project: WebF0x/Snake
 def place_nugget_at_position(self, position):
     self.nugget = Nugget(position)