def animate(i): xs = [] ys = [] zs = [] xs2 = [] query = ( "SELECT count(a.plate), a.tgl_kunjungan FROM tb_kunjungan as a, tb_member as b WHERE a.plate = b.plate and b.jenis='mobil' GROUP BY a.tgl_kunjungan" ) stmt = '' hasil = connector.Execute(query, stmt, 4) for row in hasil["Data"]: xs.append(str(row[1])) ys.append(row[0]) query = ( "SELECT count(a.plate), a.tgl_kunjungan FROM tb_kunjungan as a, tb_member as b WHERE a.plate = b.plate and b.jenis='motor' GROUP BY a.tgl_kunjungan" ) stmt = '' hasil = connector.Execute(query, stmt, 4) for row in hasil["Data"]: xs2.append(str(row[1])) zs.append(row[0]) print(xs2) ax1.clear() ax1.plot(xs2, zs, label="Motor") ax1.plot(xs, ys, label="Mobil") ax1.legend(loc='best') ax1.set_ylabel("Jumlah Kendaraan")
def Simpan(self, e): try: plate = self.plate.GetValue() keterangan = self.keterangan.GetValue() tanggal = self.tanggal.GetValue() keterangan2 = self.keteranganrek.GetValue() tanggalrek = "{0}-{1}-{2}".format(tanggal.GetYear(), int(tanggal.GetMonth()) + 1, tanggal.GetDay()) tanggalini = datetime.datetime.now() tanggalini = "{0}".format(str(tanggalini)[:10]) query = ( "UPDATE tb_kunjungan set keterangan = %s , rekomendasi = %s, keterangan2 = %s WHERE plate = %s and tgl_kunjungan = %s" ) stmt = (keterangan, tanggalrek, keterangan2, plate, tanggalini) connector.Execute(query, stmt, 1) dlg = wx.MessageDialog(self, "Data Tersimpan", "Perhatian", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() except Exception as e: dlg = wx.MessageDialog(self, "Gagal Tersimpan", "Perhatian", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal()
def __init__(self, *arg, **kwargs): super(SmsFrame, self).__init__(*arg, **kwargs, size=(700, 500)) panel = wx.Panel(self) panel.SetBackgroundColour(wx.WHITE) wx.StaticText(self, -1, "Cari", pos=(10, 10)) wx.TextCtrl(self, -1, pos=(10, 40), size=(650, 30)) self.dataOlv = ObjectListView(self, -1, style=wx.LC_REPORT | wx.SUNKEN_BORDER, pos=(10, 100), size=(650, 350)) self.dataOlv.SetColumns([ ColumnDefn("No", "left", 150, "no_telp"), ColumnDefn("Tanggal Terkirim", "left", 130, "tgl"), ColumnDefn("Isi Pesan", "left", 240, 'isi') ]) query = ( "SELECT a.no_telp, a.tanggal, a.keterangan FROM tb_sms_terkirim as a" ) stmt = '' hasil = connector.Execute(query, stmt, 4) sql = hasil["Data"] data = [] for i in sql: dict = {"no_telp": i[0], "tgl": i[1], "isi": i[2]} data.append(dict) self.dataOlv.SetObjects(data) self.SetTitle("SMS Archive") self.Show(True)
def tampilMysql(self): self.dataMobil = [] #--Getting Data Mobil From Mysql query = "SELECT * FROM tb_member ORDER BY added_date DESC" stmt = '' hasil = connector.Execute(query, stmt, 2) if hasil != 'Koneksi Gagal': data = hasil['Data'] for i in data: self.tanggalIni = str(i[2]) dict = { 'plate': i[0], 'nama': i[1], 'tanggal': "{0}".format(self.tanggalIni[:10]), 'warna': i[4], 'merk': i[5], 'perusahaan': i[6], 'model': i[7], 'tahun': i[8], 'jenis': i[9], "telp": i[10] } self.dataMobil.append(dict) else: wx.MessageBox(message="Cek Koneksi Anda", caption="Error", style=wx.OK | wx.ICON_INFORMATION)
def __init__(self, *arg, **kwargs): super(SmsFrame, self).__init__(*arg, **kwargs, size=(700, 500)) panel = wx.Panel(self) panel.SetBackgroundColour(wx.WHITE) wx.StaticText(self, -1, "Penerima", pos=(10, 10)) self.nomor = wx.TextCtrl(self, -1, pos=(10, 40), size=(300, 30)) self.boxmsg = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE, pos=(330, 40), size=(330, 350)) self.send = wx.Button(self, -1, "Kirim", pos=(330, 400)) wx.Button(self, -1, "Batal", pos=(420, 400)) self.pilihb = wx.Button(self, -1 , "Pilih", pos=(510, 400)) self.pilihb.Bind(wx.EVT_BUTTON, self.pilih) self.send.Bind(wx.EVT_BUTTON, self.kirim) self.dataOlv = ObjectListView(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER, pos=(10, 100), size=(300,350)) self.dataOlv.SetColumns([ ColumnDefn("No", "left", 150, "no_telp"), ColumnDefn("Nama", "left", 100, "nama") ]) query = ("SELECT nama_pel, no_telp FROM tb_member") stmt = '' hasil = connector.Execute(query, stmt, 4) sql = hasil["Data"] data = [] for i in sql: dict = {"no_telp": i[0], "nama": i[1]} data.append(dict) self.dataOlv.SetObjects(data) self.SetTitle("Sms Gateway") self.Show(True)
def deleteData(self, e): ind = self.dataOlv.GetFirstSelected() if ind >= 0: self.item = self.dataOlv.GetItem(ind) self.item2 = self.dataOlv.GetItem(ind, 1) query = ("DELETE FROM tb_member WHERE plate = %s and nama_pel = %s") stmt = (self.item.GetText(), self.item2.GetText()) connector.Execute(query, stmt, 1) self.tampilMysql() self.setDataMobil()
def saveData(self, e): self.getValueTextBox() if self.txtPilihan.GetValue() == 'add': if self.nomor == '' or self.nama == '' or self.telp == '' or self.merk == '' or self.model == '' or self.perusahaan == '' or self.warna == '' or self.jenis == '' or self.tahun == '': dlg = wx.MessageDialog(self, "Pastikan Data Sudah Penuh", "Perhatian", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() return else: query = ( "INSERT INTO tb_member (plate, nama_pel, added_date, warna, merk, perusahaan, model, tahun, jenis, no_telp) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" ) stmt = (self.nomor.upper(), self.nama, datetime.datetime.now(), self.warna.upper(), self.merk.upper(), self.perusahaan.upper(), self.model.upper(), self.tahun, self.jenis.upper(), self.telp) hasil = connector.Execute(query, stmt, 1) self.tampilMysql() self.setDataMobil() self.delValueTextBox() elif self.txtPilihan.GetValue() == "edit": query = ( "UPDATE tb_member SET nama_pel = %s, warna = %s, merk = %s, perusahaan = %s, model = %s, tahun = %s, jenis = %s, no_telp = %s WHERE plate = %s" ) stmt = (self.nama, self.warna.upper(), self.merk.upper(), self.perusahaan.upper(), self.model.upper(), self.tahun, self.jenis.upper(), self.telp, self.nomor.upper()) connector.Execute(query, stmt, 1) self.tampilMysql() self.setDataMobil() self.delValueTextBox() self.txtPilihan.SetValue('add') self.txtNomor.Enable()
def kirim(self, e): no_telp = self.nomor.GetValue() msg = self.boxmsg.GetValue() account_sid = "AC3cddc95d61ca0bb2e33dc5f8b48c93e8" auth_token = "f8d01a882f7e58b8b87d34fe1c6f1865" client = Client(account_sid, auth_token) message = client.messages.create( to=no_telp, from_="+15863718428", body=msg ) tglhari = datetime.datetime.now().date() query = ("INSERT INTO tb_sms_terkirim (status, no_telp, tanggal, keterangan) VALUES (%s,%s,%s,%s)") stmt = ("terkirim", no_telp, tglhari, msg) connector.Execute(query, stmt, 1)
def editData(self, e): ind = self.dataOlv.GetFirstSelected() if ind >= 0: self.item = self.dataOlv.GetItem(ind) self.item2 = self.dataOlv.GetItem(ind, 1) query = ("SELECT * FROM tb_member WHERE plate = %s and nama_pel = %s") stmt = (self.item.GetText(), self.item2.GetText()) hasil = connector.Execute(query, stmt, 4) data = hasil['Data'] self.txtNomor.SetValue(data[0][0]) self.txtNama.SetValue(data[0][1]) self.txtTelp.SetValue(data[0][10]) self.txtMerk.SetValue(data[0][5]) self.txtModel.SetValue(data[0][7]) self.txtPerusahaan.SetValue(data[0][6]) self.txtWarna.SetValue(data[0][4]) self.txtJenis.SetValue(data[0][9]) self.txtTahun.SetValue(data[0][8]) self.txtPilihan.SetValue("edit") self.txtNomor.Disable()
def setSearch(self): varSearch = self.txtSearch.GetValue() valSort = self.txtSort.GetValue() if valSort == "Nomor Plat": query = ("SELECT * FROM tb_member WHERE plate LIKE %s") elif valSort == "Tanggal": query = ("SELECT * FROM tb_member WHERE added_date LIKE %s") elif valSort == "Perusahaan": query = ("SELECT * FROM tb_member WHERE perusahaan LIKE %s") elif valSort == 'Jenis': query = ("SELECT * FROM tb_member WHERE jenis LIKE %s") else: query = ("SELECT * FROM tb_member WHERE nama_pel LIKE %s") stmt = ("%" + varSearch + "%") self.datasek = [] hasil = connector.Execute(query, stmt, 3) if hasil != 'Koneksi Gagal': data = hasil['Data'] for i in data: self.tanggalIni = str(i[2]) dict = { 'plate': i[0], 'nama': i[1], 'tanggal': "{0}".format(self.tanggalIni[:10]), 'warna': i[4], 'merk': i[5], 'perusahaan': i[6], 'model': i[7], 'tahun': i[8], 'jenis': i[9], "telp": i[10] } self.datasek.append(dict) else: wx.MessageBox(message="Cek Koneksi Anda", caption="Error", style=wx.OK | wx.ICON_INFORMATION)
def recognize(self, e): query = ("SELECT * FROM tb_member WHERE plate = %s") stmt = (self.TxtPlate.GetValue()) hasil = connector.Execute(query, stmt, 3) dataSql = hasil["Data"] if len(dataSql) == 0: dlg = wx.MessageDialog(self, "Data Belum Ada", "Perhatian", wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() if len(dataSql) > 0: self.dict = [{ "camera": "Camera 1", "time": str(datetime.datetime.now().time()), "merk": dataSql[0][5], "perusahaan": dataSql[0][6], "model": dataSql[0][7], "warna": dataSql[0][4], "tahun": dataSql[0][8], "plate": self.TxtPlate.GetValue().upper() }] self.dataOlv.SetObjects(self.dict) tanggalini = datetime.datetime.now() query = ( "SELECT keterangan2, rekomendasi FROM tb_kunjungan WHERE plate = %s and tgl_kunjungan = %s" ) stmt = (self.TxtPlate.GetValue(), "{0}".format(str(tanggalini)[:10])) datarek = connector.Execute(query, stmt, 4) hasilrek = datarek["Data"] print(hasilrek) if len(hasilrek) > 0: self.kepentinganText.SetLabel(hasilrek[0][0]) self.rekomendasiText.SetLabel(str(hasilrek[0][1])) else: self.kepentinganText.SetLabel("Belum Terdaftar") self.rekomendasiText.SetLabel("Belum Terdaftar") platea = self.TxtPlate.GetValue() self.plateNumberPlat.SetLabel(self.TxtPlate.GetValue().upper()) if len(dataSql) > 0: tanggal = str(dataSql[0][2]) self.nameDatabaseRecog.SetLabel(dataSql[0][1]) self.dateAddedRecog.SetLabel("{0}".format(tanggal[:10])) self.latestVisitDatabaseRecog.SetLabel(str(dataSql[0][11])) query = ("SELECT * FROM tb_kunjungan WHERE plate IN (%s)") stmt = (platea) jmlSql = connector.Execute(query, stmt, 3) datajmlh = jmlSql['Data'] self.visitDatabaseRecog.SetLabel(str(len(datajmlh) + 1)) query = ( "INSERT INTO tb_kunjungan (plate, tgl_kunjungan) VALUES (%s, %s)" ) stmt = (dataSql[0][0], datetime.datetime.now()) hasilSql = connector.Execute(query, stmt, 1) query = ("UPDATE tb_member SET latest_visit = %s WHERE plate = %s") stmt = (datetime.datetime.now(), dataSql[0][0]) hasilSql = connector.Execute(query, stmt, 1) else: self.nameDatabaseRecog.SetLabel("Tidak Terdaftar") self.dateAddedRecog.SetLabel("Tidak Terdaftar") self.latestVisitDatabaseRecog.SetLabel("Hari Ini") self.visitDatabaseRecog.SetLabel("1") query = ( "INSERT INTO tb_kunjungan (plate, tgl_kunjungan) VALUES (%s, %s)" ) stmt = (platea, datetime.datetime.now()) hasilSql = connector.Execute(query, stmt, 1)
def recognition(self, e): print(self.pathp) if self.pathp == '': self.ret, self.image = self.capture.read() print(self.ret) print(self.image) if os.path.exists("itemp\plate\plat1.jpg"): self.imageName = "itemp\plate\plat_{0}.jpg".format( int(time.time())) cv2.imwrite(self.imageName, self.image) self.jsonName = "itemp\json\json_{0}.json".format( int(time.time())) else: self.imageName = "itemp\plate\plat1.jpg" cv2.imwrite(self.imageName, self.image) self.jsonName = "itemp\json\json1.json" bitmap = wx.Bitmap(self.imageName) bitmap = scale_bitmap(bitmap, 280, 200) control = wx.StaticBitmap(self, -1, bitmap) control.SetPosition((720, 420)) IMAGE_PATH = self.imageName else: IMAGE_PATH = self.pathp SECRET_KEY = 'sk_42b18388bc96def5ad015425' with open(IMAGE_PATH, 'rb') as image_file: img_base64 = base64.b64encode(image_file.read()) url = 'https://api.openalpr.com/v2/recognize_bytes?recognize_vehicle=1&country=id&secret_key=%s' % ( SECRET_KEY) try: r = requests.post(url, data=img_base64) except Exception as e: print("Error: Kendaraan Tidak Ditemukan") return data_file = json.dumps(r.json(), indent=2) data = json.loads(str(data_file)) hasil = data['results'][0] tanggalini = datetime.datetime.now() query = ( "SELECT keterangan2, rekomendasi FROM tb_kunjungan WHERE plate = %s and tgl_kunjungan = %s" ) stmt = (hasil['plate'], "{0}".format(str(tanggalini)[:10])) datarek = connector.Execute(query, stmt, 4) hasilrek = datarek["Data"] print(hasilrek) if len(hasilrek) > 0: self.kepentinganText.SetLabel(str(hasilrek[0][0])) self.rekomendasiText.SetLabel(str(hasilrek[0][1])) else: self.kepentinganText.SetLabel("Belum Terdaftar") self.rekomendasiText.SetLabel("Belum Terdaftar") query = ("SELECT * FROM tb_member WHERE plate IN (%s)") stmt = (hasil['plate']) hasilSql = connector.Execute(query, stmt, 3) dataSql = hasilSql['Data'] print(dataSql) if len(dataSql) > 0: self.dict = { "camera": "Camera 1", "time": str(datetime.datetime.now().time()), "merk": dataSql[0][5], "perusahaan": dataSql[0][6], "model": dataSql[0][7], "warna": dataSql[0][4], "tahun": dataSql[0][8], "plate": hasil['plate'] } else: self.plateMobil = hasil['plate'] self.warnaMobil = hasil["vehicle"]['color'][0]['name'].upper() self.merkMobil = hasil["vehicle"]['make_model'][0]['name'].upper(), self.perusahaanMobil = hasil["vehicle"]['make'][0]['name'].upper() self.tahunMobil = str(hasil["vehicle"]['year'][0]['name']) self.modelMobil = hasil["vehicle"]['body_type'][0]['name'].upper() self.dict = { "camera": "Camera 1", "time": str(datetime.datetime.now().time()), "merk": self.merkMobil, "perusahaan": self.perusahaanMobil, "model": self.modelMobil, "warna": self.warnaMobil, "tahun": self.tahunMobil, "plate": self.plateMobil } self.plateNumberPlat.SetLabel(hasil['plate']) self.text.SetLabel(hasil['plate']) if len(dataSql) > 0: tanggal = str(dataSql[0][2]) self.nameDatabaseRecog.SetLabel(dataSql[0][1]) self.dateAddedRecog.SetLabel("{0}".format(tanggal[:10])) self.latestVisitDatabaseRecog.SetLabel(str(dataSql[0][11])) query = ("SELECT * FROM tb_kunjungan WHERE plate IN (%s)") stmt = (hasil['plate']) jmlSql = connector.Execute(query, stmt, 3) datajmlh = jmlSql['Data'] self.visitDatabaseRecog.SetLabel(str(len(datajmlh) + 1)) query = ( "INSERT INTO tb_kunjungan (plate, tgl_kunjungan) VALUES (%s, %s)" ) stmt = (dataSql[0][0], datetime.datetime.now()) hasilSql = connector.Execute(query, stmt, 1) query = ("UPDATE tb_member SET latest_visit = %s WHERE plate = %s") stmt = (datetime.datetime.now(), dataSql[0][0]) hasilSql = connector.Execute(query, stmt, 1) else: self.nameDatabaseRecog.SetLabel("Tidak Terdaftar") self.dateAddedRecog.SetLabel("Tidak Terdaftar") self.latestVisitDatabaseRecog.SetLabel("Hari Ini") self.visitDatabaseRecog.SetLabel("1") query = ( "INSERT INTO tb_kunjungan (plate, tgl_kunjungan) VALUES (%s, %s)" ) stmt = (hasil['plate'], datetime.datetime.now()) hasilSql = connector.Execute(query, stmt, 1) candidates = hasil['candidates'] e = [] for i in candidates: Candidates = { 'confidences': str(int(i['confidence'])) + " " + "%", 'plate': i['plate'] } e.append(Candidates) self.dataOlv.SetColumns([ ColumnDefn("Camera", "left", 100, "camera"), ColumnDefn("Time", "left", 100, "time"), ColumnDefn("Plate", "left", 100, "plate"), ColumnDefn("Merk", "left", 100, "merk"), ColumnDefn("Perusahaan", "left", 102, "perusahaan"), ColumnDefn("Model", "left", 100, "model"), ColumnDefn("Warna", "left", 100, "warna"), ColumnDefn("Tahun", "left", 100, "tahun") ]) self.dataMobilTampil.append(self.dict) self.dataOlv.SetObjects(self.dataMobilTampil) self.dataOlvCand.SetColumns([ ColumnDefn("Plate", 'left', 100, 'plate'), ColumnDefn("confidence", 'left', 100, 'confidences') ]) self.dataOlvCand.SetObjects(e) credit = { "credit": 2000, "digunakan": data['credits_monthly_used'], "sisa": 2000 - int(data['credits_monthly_used']) } self.dataOlvCre.SetColumns([ ColumnDefn("Credit", "left", 100, "credit"), ColumnDefn("Digunakan", "left", 100, "digunakan"), ColumnDefn("Sisa", "left", 100, "sisa") ]) self.dataCredit.append(credit) self.dataOlvCre.SetObjects(self.dataCredit)
def basicGui(self): menuBar = wx.MenuBar() #set up Menu Bar fileButton = wx.Menu() messageButton = wx.Menu() dataButton = wx.Menu() grafikButton = wx.Menu() settingButton = wx.Menu() helpButton = wx.Menu() panel = wx.Panel(self) panel.SetBackgroundColour(wx.WHITE) #Start Menu Bar Item #---File Item--# #openItem = fileButton.Append(wx.ID_OPEN, '&Open', "Open Button") #saveItem = fileButton.Append(wx.ID_SAVE, '&Save', 'Save Button') exitItem = fileButton.Append(wx.ID_EXIT, '&Exit', "Exit Button") #--Data Item--# mobilItem = dataButton.Append(wx.ID_ANY, '&Data Kendaraan', "Data Kendaraan") #--Grafik Item--# perhariItem = grafikButton.Append(wx.ID_ANY, "&Grafik kendaraan", "Grafik Kendaraan Per Hari") messageItem = messageButton.Append(wx.ID_ANY, "&Kirim SMS", "Kirim SMS") messageItem2 = messageButton.Append(wx.ID_ANY, "&SMS Terkirim", "SMS Terkirim") #End Menu Bar Item #Appending to Form menuBar.Append(fileButton, 'File') menuBar.Append(dataButton, 'Data') menuBar.Append(grafikButton, 'Grafik') menuBar.Append(messageButton, "Message") self.SetMenuBar(menuBar) #event self.Bind(wx.EVT_MENU, self.Quit, exitItem) self.Bind(wx.EVT_MENU, self.data_kendaraan_Click, mobilItem) self.Bind(wx.EVT_MENU, self.sms_click, messageItem) self.Bind(wx.EVT_MENU, self.archived, messageItem2) self.Bind(wx.EVT_MENU, self.graphic, perhariItem) #Create Tab nb = wx.Notebook(panel) tab2 = TabTwo(nb) tab3 = TabThree(nb) nb.AddPage(tab2, "Recognition") nb.AddPage(tab3, "Manual") sizer = wx.BoxSizer() sizer.Add(nb, 1, wx.EXPAND) panel.SetSizer(sizer) #----End Tab---- tglhari = datetime.datetime.now().date() try: query = ( "select a.keterangan2, b.no_telp, a.id_kunjungan from tb_kunjungan as a, tb_member as b WHERE a.plate = b.plate and a.status='belum' and a.rekomendasi = %s" ) stmt = (str(tglhari)) hasil = connector.Execute(query, stmt, 3) for row in hasil["Data"]: account_sid = "AC3cddc95d61ca0bb2e33dc5f8b48c93e8" auth_token = "f8d01a882f7e58b8b87d34fe1c6f1865" client = Client(account_sid, auth_token) message = client.messages.create(to=row[1], from_="+15863718428", body=row[0]) print(message.sid) query = ( "UPDATE tb_kunjungan set status = %s WHERE tgl_kunjungan = %s" ) stmt = ("terkirim", str(tglhari)) connector.Execute(query, stmt, 1) query = ( "INSERT INTO tb_sms_terkirim (id_kunjungan, status, no_telp, tanggal, keterangan) VALUES (%s,%s,%s,%s,%s)" ) stmt = (row[2], "terkirim", row[1], tglhari, row[0]) connector.Execute(query, stmt, 1) if hasil == 'Koneksi Gagal': self.textStat = 'Not Connected' else: self.textStat = "Connected" except Exception as e: self.textStat = 'Not Connected' today = datetime.datetime.now() self.StatusBar = self.CreateStatusBar(3) self.StatusBar.SetStatusText("Welcome To ALPR System") self.StatusBar.SetStatusWidths([500, 600, 100]) self.StatusBar.SetStatusText( calendar.day_name[today.weekday()] + ',' + ' ' + '{0}'.format(str(today)[:10]), 1) self.StatusBar.SetStatusText("Status : " + self.textStat, 2) self.Show() self.SetTitle('Automatic License Plate Recognition') self.Show(True) self.Maximize()