Beispiel #1
0
    def act(self, event_name, state):
        exp = Expense()
        pipeline = [{
            '$match': {
                'name': event_name
            }
        }, {
            '$group': {
                '_id': "$peoplename",
                'total': {
                    '$sum': "$total"
                }
            }
        }]

        res = list(exp.aggregate(pipeline))
        if len(res) == 0:
            event_name = event_name.replace("_", " ")
            out = "maaf, tidak ada yang ikut acara " + event_name + " :("
            return (state, out)

        # avg = reduce(lambda x,y: x+float(y['total']), res, 0) / len(res)
        # print(avg)
        def reducer(prev, cur):
            if prev == "":
                prev = "List ikut (" + str(len(res)) + " orang)"
            return prev + '\n' + '{0} ikut'.format(cur['_id'])

        out = reduce(reducer, res, '')

        return (state, out)
Beispiel #2
0
    def act(self, event_name, pengeluaran_name, people_name, state, duit=-1):
        if Event().searchOne({"lineid": state['id'], "about": event_name}):
            duit = float(duit)
            if duit < 0:
                state = {
                    **state, 'pengeluaran_name': pengeluaran_name,
                    'event_name': event_name,
                    'people_name': people_name,
                    'before_state': state['state_id']
                }
                return (
                    state,
                    "Masukkan jumlah duit \nBisa lewat teks atau input bon")

            try:
                ev1 = Expense(state['id'], pengeluaran_name, event_name,
                              people_name, duit)
                ev1.create()
                event_name = event_name.replace("_", " ")
                pengeluaran_name = pengeluaran_name.replace("_", " ")
                return (state, "Pengeluaran " + pengeluaran_name +
                        " telah ditambahkan di acara " + event_name)
            except:
                print(sys.exc_info())
                return (state, errorCreateUpdatePengeluaran)
        else:
            event_name = event_name.replace("_", " ")
            return (state, "acara " + event_name + " belum ada :( ")
Beispiel #3
0
    def act(self, event_name, pengeluaran_name, people_name, duit, state):

        if Event().searchOne({"lineid": state['id'], "about": event_name}):
            try:
                ex1 = Expense(state['id'], pengeluaran_name, event_name,
                              people_name, duit)
                ex1.update()

                pengeluaran_name = pengeluaran_name.replace("_", " ")
                return (state, "Pengeluaran " + pengeluaran_name +
                        " berhasil dirubah")
            except:
                print(sys.exc_info())
                return (state, errorCreateUpdatePengeluaran)
        else:
            event_name = event_name.replace("_", " ")
            return (state, "acara " + event_name + " belum ada :( ")
Beispiel #4
0
 def act(self, event_name, people_name, state):
     try:
         ex1 = Expense(state['id'], 'ikut', event_name, people_name, 0)
         ev1 = Expense()
         ev1.removeQuery({
             "lineid": state['id'],
             "about": 'ikut',
             "name": event_name,
             "peoplename": people_name
         })
         event_name = event_name.replace("_", " ")
         return (state, people_name + " tidak jadi ikut pada " + event_name)
     except:
         return (
             state,
             "Maaf kak, bawel ga ngerti, coba nambahjadwalnya kaya gini ya kak'si bawel gajadi ikut acara/event/jadwal nonton bareng oleh kevin'"
         )
Beispiel #5
0
 def act(self, event_name, people_name, state):
     try:
         if Event().searchOne({"lineid": state['id'], "about": event_name}):
             ex1 = Expense(state['id'], 'ikut', event_name, people_name, 0)
             ex1.create()
             event_name = event_name.replace("_", " ")
             return (state,
                     people_name + " berhasil ikut pada " + event_name)
         else:
             event_name = event_name.replace("_", " ")
             return (state, "acara " + event_name + " belum ada :( ")
     except:
         print(sys.exc_info())
         return (
             state,
             "Maaf kak, bawel ga ngerti, coba nambahjadwalnya kaya gini ya kak'si bawel ikut acara/event/jadwal nonton bareng oleh kevin'"
         )
Beispiel #6
0
    def act(self, event_name, state):
        exp = Expense()
        pipeline = [{
            '$match': {
                'name': event_name
            }
        }, {
            '$group': {
                '_id': "$peoplename",
                'total': {
                    '$sum': "$total"
                }
            }
        }]

        res = list(exp.aggregate(pipeline))
        if len(res) == 0:
            event_name = event_name.replace("_", " ")
            out = "maaf, tidak ada pengeluaran untuk " + event_name + " :("
            return (state, out)
        print(res)
        avg = reduce(lambda x, y: x + float(y['total']), res, 0) / len(res)
        print(avg)

        def reducer(prev, cur):
            diff = cur['total'] - avg
            if prev == "":
                prev = "List bayar membayar"
            if (diff > 0):
                return prev + '\n' + 'si {0} dapet {1}'.format(
                    cur['_id'], "%.0f" % diff)
            return prev + '\n' + ' si {0} harus bayar {1}'.format(
                cur['_id'], "%.0f" % abs(diff))

        out = reduce(reducer, res, '')

        return (state, out)
Beispiel #7
0
 def act(self, jumlah, path, state):
     ev1 = Expense(state['id'], state['pengeluaran_name'],
                   state['event_name'], state['people_name'], jumlah)
     ev1.create()
     ev1.updatePathNota(str(path))
     pengeluaran_name = state['pengeluaran_name'].replace("_", " ")
     state.pop('pengeluaran_name', None)
     state.pop('event_name', None)
     state.pop('people_name', None)
     state.pop('before_state', None)
     return (state, "Pengeluaran " + pengeluaran_name +
             " berhasil ditambahkan dengan senilai " + jumlah)
Beispiel #8
0
 def act(self, event_name, state, pengeluaran_name=""):
     ex1 = Expense()
     if pengeluaran_name == "":
         ex1.removeQuery({"lineid": state['id'], "name": event_name})
         event_name = event_name.replace("_", " ")
         return (state, "Semua pengeluaran untuk acara " + event_name +
                 " telah dihapus")
     else:
         ex1.removeQuery({
             "lineid": state['id'],
             "about": pengeluaran_name,
             "name": event_name
         })
         event_name = event_name.replace("_", " ")
         pengeluaran_name = pengeluaran_name.replace("_", " ")
         return (state, "Pengeluaran " + pengeluaran_name +
                 " untuk acara " + event_name + " telah dihapus")
Beispiel #9
0
    def act(self, state, event_name=""):
        try:
            ex1 = Expense()
            if event_name == "":
                expenses = ex1.search({"lineid": state['id']})
            else:
                expenses = ex1.search({
                    "lineid": state['id'],
                    "name": event_name
                })

            if expenses.count() == 0:
                if event_name == "":
                    output = "Maaf tidak ada pengeluaran di database bawel :("
                else:
                    event_name = event_name.replace("_", " ")
                    output = "Maaf tidak ada pengeluaran di acara " + event_name + " di database bawel :("
                return (state, output)
            licc = []
            ite = 0
            ikut = 9
            liexpenses = []
            for expense in expenses:
                if expense['about'] == "ikut":
                    continue
                ite += 1
                about = "Pengeluaran " + expense['about'].replace("_", " ")
                event_name = expense['name'].replace("_", " ")[0:20]
                amount = str(expense['total'])[0:10]
                people_name = str(expense['peoplename'])[0:10]
                text = "acara " + event_name + " sebesar " + amount + " oleh " + people_name
                report = '/reportpengeluaran ' + expense['name']
                hapus = '/hapuspengeluaran ' + expense['name'] + " " + expense[
                    'about']
                actionli = [
                    PostbackTemplateAction(label='Report Pengeluaran',
                                           data=report),
                    # PostbackTemplateAction(label='Hapus Pengeluaran', data=hapus)
                ]
                if expense.get('pathnota') and expense['pathnota'] != "":
                    actionli.append(
                        URITemplateAction(label='go to nota',
                                          uri=expense['pathnota']))
                else:
                    actionli.append(
                        URITemplateAction(label='tidak ada nota',
                                          uri='http://google.com'))

                cc = CarouselColumn(text=text, title=about, actions=actionli)
                licc.append(cc)
                if ite == 4:
                    carousel_template = CarouselTemplate(columns=licc)
                    template_message = TemplateSendMessage(
                        alt_text='List pengeluaran',
                        template=carousel_template)
                    ite = 0
                    liexpenses.append(template_message)
                    licc = []
            if len(licc) == 0 and len(liexpenses) == 0:
                if event_name == "":
                    output = "Maaf tidak ada pengeluaran di database bawel :("
                else:
                    event_name = event_name.replace("_", " ")
                    output = "Maaf tidak ada pengeluaran di acara " + event_name + " di database bawel :("
                return (state, output)
            if ite > 0:
                carousel_template = CarouselTemplate(columns=licc)
                template_message = TemplateSendMessage(
                    alt_text='List pengeluaran', template=carousel_template)
                liexpenses.append(template_message)
            return (state, liexpenses)
        except:
            print(sys.exc_info())