예제 #1
0
def add_attribute():
  try:
    current_concept = request.json["old_concept"]
    current_lattice = request.json["old_lattice"]
    attrM = request.json["attrM"]
    attrMI = request.json["attrMI"]

    a = core.Context(current_concept["G"],
        current_concept["M"],
        current_concept["I"])
    b = core.Lattice(
      list(map(lambda x: core.Node(set(x["G"]), set(x["M"])), current_lattice["C"])), 
      set(map(lambda x: (int(x[0]), int(x[1])), current_lattice["E"]))
    )
    start = datetime.now()
    (newCtx, L) = addAttribute.addAttr(a, b, attrM, attrMI)
    end = datetime.now()

    draw_start = datetime.now()
    draw.draw(L, OUT_FILE_NAME)
    draw_end = datetime.now()

    resp = dict({
      'latticeImg': encodedFile(OUT_FILE_NAME),
      'lattice': b.toJson(),
      'concept': a.toJson(),
      'drawTime': (draw_end - draw_start).total_seconds(),
      'addTime': (end - start).total_seconds(),
      'json': json.dumps(dict(G = newCtx.G, M = newCtx.M, I = newCtx.I)) 
    })
    return jsonify(resp)
  except:
    return "Wrong input", 400
예제 #2
0
def fileUpload():
    file = request.files['file'] 
    destination="/".join([os.path.realpath(os.path.dirname(__file__)), "concept2.json"])
    file.save(destination)
    ###
    concept = getFromJson("concept2")
    try:
      check_import_concept(concept)
    except Exception as e:
      return "{0}".format(e), 400

    a = core.Context(concept["G"],
        concept["M"],
        concept["I"])
    start = datetime.now()
    b = nextNeighbour.nextNeighbours(a)
    end = datetime.now()

    draw_start = datetime.now()
    draw.draw(b, OUT_FILE_NAME)
    draw_end = datetime.now()

    resp = dict({
      'latticeImg': encodedFile(OUT_FILE_NAME),
      'lattice': b.toJson(),
      'concept': a.toJson(),
      'constructTime': (end - start).total_seconds(),
      'drawTime': (draw_end - draw_start).total_seconds(),
      'json': json.dumps(dict(G = a.G, M = a.M, I = a.I)) 
    })
    return jsonify(resp)
예제 #3
0
def this(key=None, value=None):
    '''
    1. when key, and value are None,
    return the current testcase(aka `It`) or testsuite(aka `describe`)

    2. when key is set and value is None,
    return the local variable's value.
    It's a shortcut for `this().get(key)`

    3. when key and value are set,
    set the local variable key = value.
    It's a shortcut for `this().set(key, value)`

    arguments:
    key -- local var name
    value -- local var value

    return:
    1. current `It` or `describe`
    2. current variable
    3. None
    '''
    if key is None:
        t = core.Context().current
        if not t == core.World():
            return t
    elif value is None:
        return this().get(key)
    else:
        this().set(key, value)
예제 #4
0
def on_message(slack, config, message):
    # Respond to all types of messages.
    channel_id = message['channel']
    if channel_id[0] in ['C', 'G']:
        # Channel/group message, make sure foosbot is being addressed.
        if not re.search("<@{}>".format(config['bot_id']), message['text']):
            return
        pass
    sender = message['user']
    text = message['text'].lower()

    context = core.Context(slack=slack,
                           channel=channel_id,
                           sender=sender,
                           bot_id=config['bot_id'],
                           users=config['users'],
                           matches=loldb.getmatches())

    # Look for HELP
    matches_help = re.search(help_command, text)
    if matches_help:
        core.reply_with_message(help_message, context)
        return

    # Look for RANK
    matches_rank = re.search(rank_command, text)
    if matches_rank:
        core.rank(context)
        return

    # Look for STATS
    matches_stats = re.search(stats_command, text)
    if matches_stats:
        core.stats(users=users_in(matches_stats.group('who')), context=context)
        return

    # Look for RESULTS
    matches_results = re.search(results_command, text)
    if matches_results:
        core.results(users=users_in_teams(matches_results.group('who')),
                     score1=matches_results.group('score1'),
                     score2=matches_results.group('score2'),
                     context=context)
        return

    # Look for PREDICT
    matches_predict = re.search(predict_command, text)
    if matches_predict:
        core.predict(users=users_in_teams(matches_predict.group('who')), context=context)
        return

    # Look for DELETE
    matches_delete = re.search(delete_command, text)
    if matches_delete:
        core.delete(game_id=matches_delete.group('what'), context=context)
        return

    core.reply_with_message(didnt_understand_message, context)
예제 #5
0
    def __init__(self):
        self.context = core.Context(tf2_api=api.API(TF2_WIKI_API),
                                    wikipedia_api=api.API(WIKIPEDIA_API))
        self.last_input = ''

        super().__init__()

        self.title('wikitranslator')
        self.protocol('WM_DELETE_WINDOW', self.exit)

        self.frame = ttk.Frame(self, padding='3 3 3 3', style='Wat.TFrame')

        self.text_input = tk.Text(self.frame,
                                  width=90,
                                  height=40,
                                  wrap='char',
                                  undo=True,
                                  maxundo=100)
        self.scrollbar_input = ttk.Scrollbar(self.frame,
                                             orient='vertical',
                                             command=self.text_input.yview)

        self.text_output = tk.Text(self.frame,
                                   width=90,
                                   height=40,
                                   wrap='char',
                                   state=tk.DISABLED)
        self.scrollbar_output = ttk.Scrollbar(self.frame,
                                              orient='vertical',
                                              command=self.text_output.yview)

        self.control_panel = ControlPanel(self.frame,
                                          self.translate,
                                          padding='3 3 3 3')

        self.frame.grid(column=0, row=0, sticky='nwes')

        self.control_panel.grid(column=0, row=0, sticky='nwes')
        self.text_input.grid(column=0, row=1, sticky='nwes')
        self.scrollbar_input.grid(column=1, row=1, sticky='nwes')
        self.text_output.grid(column=2, row=1, sticky='nwes')
        self.scrollbar_output.grid(column=3, row=1, sticky='nwes')

        self.text_input['yscrollcommand'] = self.scrollbar_input.set
        self.text_output['yscrollcommand'] = self.scrollbar_output.set

        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.frame.rowconfigure(1, weight=1, minsize=150)
        self.frame.columnconfigure(0, weight=2, minsize=400)
        self.frame.columnconfigure(2, weight=2, minsize=400)

        self.bind('<Control-Z>', self.text_input.edit_undo)
        self.bind('<Control-Shift-Z>', self.text_input.edit_redo)

        self.after(1000, self.input_tick)
예제 #6
0
def hello_app():
    concept = getFromJson("concept")
    a = core.Context(concept["G"],
        concept["M"],
        concept["I"])
    start = datetime.now()
    b = nextNeighbour.nextNeighbours(a)
    end = datetime.now()

    draw_start = datetime.now()
    draw.draw(b, OUT_FILE_NAME)
    draw_end = datetime.now()

    resp = dict({
      'latticeImg': encodedFile(OUT_FILE_NAME),
      'lattice': b.toJson(),
      'concept': a.toJson(),
      'constructTime': (end - start).total_seconds(),
      'drawTime': (draw_end - draw_start).total_seconds(),
      'json': json.dumps(dict(G = a.G, M = a.M, I = a.I)) 
    })
    return jsonify(resp)