Example #1
0
def home():
    if not flask_login.current_user.is_authenticated:
        return redirect(url_for('login'))
    else:
        my_nuggets = Nugget.objects(
            assignee__iexact=flask_login.current_user.username)
        managed_nuggets = Nugget.objects(
            assigner__iexact=flask_login.current_user.username)
        return render_template('home.html',
                               my_nuggets=my_nuggets,
                               managed_nuggets=managed_nuggets)
Example #2
0
def motd():
    mac = request.args['mac']
    nugget_obj = Nugget.objects(mac=mac).first()
    if nugget_obj == None:
        code = register_new_nugget(mac)
        return {
            'message-list': ["nugget.galletta.xyz/new/{}".format(code)],
            'delay': 5
        }
    else:
        message_list = nugget_obj['message_list']
        lat = nugget_obj['weather_lat']
        lon = nugget_obj['weather_lon']
        cached_weather = nugget_obj['cached_weather']
        if nugget_obj['display_weather'] and (
                'report' not in cached_weather or
            (time.time() - cached_weather['time']) >= 180):
            cached_weather['time'] = time.time()
            cached_weather['report'] = weather(lat, lon)
        nugget_obj.save()
        if nugget_obj['display_weather']:
            weather_data = cached_weather['report']
            current_temp = int(round(weather_data['current']['feels_like']))
            high = int(round(weather_data['daily'][0]['temp']['max']))
            low = int(round(weather_data['daily'][0]['temp']['min']))
            current_conditions = weather_data['daily'][0]['weather'][0][
                'main'] + " - " + weather_data['daily'][0]['weather'][0][
                    'description']
            weather_string = pad(
                pad("Low:" + str(low) + " High:" + str(high), 16) +
                "Now Feels " + str(current_temp) + "°F",
                32) + current_conditions
            message_list.insert(0, weather_string)
        return {'message-list': message_list, 'delay': nugget_obj['delay']}
 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 #5
0
def update(nugget_id):
    to_update = Nugget.objects(id=nugget_id).first()
    message_list = []
    data = request.form.listvalues()
    print(data)
    for message in request.form.values():
        if len(message) > 0:
            message_list.append(message)
    to_update.message_list = message_list
    to_update.save()
    flash('Updated Successfully')
    return (redirect(url_for('home')))
Example #6
0
def update_my(nugget_id):
    to_update = Nugget.objects(id=nugget_id).get()
    try:
        to_update['display_weather'] = (
            request.form['display_weather'] == 'on')
    except KeyError:
        to_update['display_weather'] = False
    to_update['weather_lat'] = request.form['weather_lat']
    to_update['weather_lon'] = request.form['weather_lon']
    to_update['delay'] = request.form['delay']
    to_update.save()
    flash('Updated Successfully')
    return (redirect(url_for('home')))
Example #7
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 #9
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 #10
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 #11
0
File: game.py Project: WebF0x/Snake
 def place_nugget_at_position(self, position):
     self.nugget = Nugget(position)