def computation(): global inCount_goingToSM global inCount_goingToCalmar global inAllSpeeds_goingToSM global inAllSpeeds_goingToCalmar try: avgSpeed_goingToSM = inAllSpeeds_goingToSM / inCount_goingToSM avgSpeed_goingToCalmar = inAllSpeeds_goingToCalmar / inCount_goingToCalmar except ZeroDivisionError: avgSpeed_goingToSM = 0 avgSpeed_goingToCalmar = 0 trafficFlow_goingToSM = inCount_goingToSM / 300 # vehicles per 5 minutes trafficFlow_goingToCalmar = inCount_goingToCalmar / 300 # vehicles per 5 minutes density_goingToSM = trafficFlow_goingToSM / 11 # vehicles per 11 meters. density_goingToCalmar = trafficFlow_goingToCalmar / 11 # vehicles per 11 meters. print( "----------------------------------------------------------------------------------------------------------" ) print("Count (To SM) = ", inCount_goingToSM) print("Average Speed (To SM) = ", avgSpeed_goingToSM) print("Traffic Flow (To SM) = ", trafficFlow_goingToSM) print("Density (To SM) = ", density_goingToSM) print("Count (To Calmar) = ", inCount_goingToCalmar) print("Average Speed (To Calmar) = ", avgSpeed_goingToCalmar) print("Traffic Flow (To Calmar) = ", trafficFlow_goingToCalmar) print("Density (To Calmar) = ", density_goingToCalmar) print("Time = ", dateTime) print( "--------------------------------------------------------------------- -------------------------------------" ) db.data_entry2_toSM(dateTime, inCount_goingToSM, avgSpeed_goingToSM, trafficFlow_goingToSM, density_goingToSM) db.data_entry2_toCalmar(dateTime, inCount_goingToCalmar, avgSpeed_goingToCalmar, trafficFlow_goingToCalmar, density_goingToCalmar) inCount_goingToSM = 0 inCount_goingToCalmar = 0 inAllSpeeds_goingToSM = 0 inAllSpeeds_goingToCalmar = 0
def main(): db = sys.argv[1] u = sys.argv[2] print "Connecting to %s with user %s" % (db, u) connect = DatabaseConnect.Connection_Factory(db, u) cur = connect.cursor() cur.execute('SELECT version()') ver = cur.fetchone() print ver
import time import lxml import requests from bs4 import BeautifulSoup import DatabaseConnect url = 'https://jn.lianjia.com/ershoufang/pg' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' } # fileName='lianjia_second.csv' db = DatabaseConnect.Db() db.connection() def parseContent(response): soup = BeautifulSoup(response, features='lxml') houses = soup.find_all('div', class_='info clear') # addresses=soup.find_all('div',class_='address') # unitPrices=soup.find_all('div',class_='unitPrice') # sql=('create table lianjia(name varchar(1000),type varchar(1000),address varchar(1000),unitprice varchar(500))') # db.opreate(sql) # with codecs.open(fileName,'a+',encoding='utf-8')as f: # title=['名称','户型','地址','单价'] # writer=csv.DictWriter(f,title)
# -*- coding: utf-8 -*- """ Created on Wed Jan 24 15:17:49 2018 @author: fviramontes8 """ import DatabaseConnect as dc db = dc.DatabaseConnect() db.connect() table_contents = db.readTable("ip") db.disconnect() #print(table_contents[0][0]) pi_details = {} for i in table_contents: pi_details[i[0]] = [i[1], i[2]] #print(pi_details) text_object = open("ip.txt", "r") #print(text_object.read()) ip_address = text_object.read() text_object.close() ip_address = ip_address.strip("\n") ip_address = ip_address.strip() #print("This computer's IP address: " + ip_address) text_object = open("mac.txt", "r") mac_address = text_object.read() text_object.close()
def __init__(self, master, init_file_name, scale): """Initiate all variables for the register program""" try: init_file = open(init_file_name) except IOError: print "Couldn't find initiation file for configuring register" self.employee_discount_enabled = False self.values_dict = ReadSettings.get_values_from_init_file(init_file) print self.values_dict # Radio variable for #self.radio_variable = Tkinter.IntVar() #self.radio_variable.set(0) # Set to grove initially self.scale = scale self.master = master self.cashierVar = Tkinter.StringVar() self.cashierVar.set(self.values_dict["register_name"]) self.cart = [] self.items = [] self.products = [] self.categories = [] self.prod_cats = [] self.prod_prices = [] self.deals = [] self.deal_prices = [] self.current_category_id = 1 self.start_time = time.time() cursor, conn = DatabaseConnect.connect(self.values_dict) # Early exit if can't connect to database if cursor is None: tkMessageBox.showwarning("Database Error", "Could not connect to database, check errors on terminal") new_ip_address = tkSimpleDialog.askstring("Manual ip address entry", "Enter ip address of host to connect to (127.0.0.1 if can't connect to network)") if new_ip_address is not None: self.values_dict["database_path"] = new_ip_address cursor, conn = DatabaseConnect.connect(self.values_dict) print "Tried connecting to manual ip address " + new_ip_address if cursor is None: tkMessageBox.showwarning("Manual ip entry failure", "Failed to connect to manual ip address, closing") master.destroy() return else: master.destroy() return # read product ordering in category preferences self.category_order_dict = read_category_order.read_category_order() self.products_db_cursor = cursor self.products_db_connect = conn self.update_info_from_database() self.transaction_number = 0 self.read_products_categories_constants() application_height = int(self.values_dict["application_height"]) application_width = int(self.values_dict["application_width"]) self.edible_tax_rate = float(self.values_dict["edible_tax_rate"]) self.nonedible_tax_rate = float(self.values_dict["nonedible_tax_rate"]) self.products_width = int(self.values_dict["products_width"]) self.cart_width = int(self.values_dict["cart_width"]) # Inside products frame, eventually read these from a file information_height = int(self.values_dict["information_height"]) categories_height = int(self.values_dict["categories_height"]) items_height = int(self.values_dict["items_height"]) debug_height = int(self.values_dict["debug_height"]) #Inside cart frame cart_info_height = int(self.values_dict["cart_info_height"]) cart_items_height = int(self.values_dict["cart_items_height"]) totals_height = int(self.values_dict["totals_height"]) payment_type_height = int(self.values_dict["payment_type_height"]) #Receipt info self.receipt_chars_per_inch = int(self.values_dict["receipt_chars_per_inch"]) print self.receipt_chars_per_inch self.master.resizable(False,False) self.products_frames = 0 self.cart_frames = 0 self.master_frame = Tkinter.Frame(master) self.master_frame.grid() # EXP --- #self.secondary_cart = Tkinter.Toplevel(master) #self.secondary_cart.title("Customer Cart View") #self.secondary_cart.resizable(False,False) #self.secondary_cart.protocol("WM_DELETE_WINDOW", self.secondary_cart.iconify) #self.secondary_cart.grid() #self.secondary_cart_frames = 0 # EXP --- #Removed functionality, possibly read later but not unless necessary self._shift_is_pressed = False self.master_frame.bind_all("<Shift_L>", self._shift_pressed) self.master_frame.bind_all("<KeyRelease-Shift_L>", self._shift_released) assert application_height == information_height + categories_height + items_height + debug_height assert application_height == cart_info_height + cart_items_height + totals_height + payment_type_height assert application_width == self.products_width + self.cart_width if CART_RIGHT: products_frame_column = 0 cart_frame_column = 1 else: products_frame_column = 1 cart_frame_column = 0 self.products_frame = add_frame(self.master_frame, self.products_width, application_height, "gray", 0, products_frame_column) self.cart_frame = add_frame(self.master_frame, self.cart_width, application_height, "gray", 0, cart_frame_column) # Products frame additions self.information_frame = self.add_products_frame(information_height, self.values_dict["information_frame_color"]) self.category_frame = self.add_products_frame(categories_height, self.values_dict["categories_frame_color"]) self.items_frame = self.add_products_frame(items_height, self.values_dict["items_frame_color"]) self.debug_frame = self.add_products_frame(debug_height, self.values_dict["debug_frame_color"]) # Cart frame additions self.payment_type_frame = self.add_cart_frame(payment_type_height, self.values_dict["payment_type_frame_color"]) self.cart_info_frame = self.add_cart_frame(cart_info_height, self.values_dict["cart_info_frame_color"]) self.cart_items_frame = self.add_cart_frame(cart_items_height, self.values_dict["cart_items_frame_color"]) self.totals_frame = self.add_cart_frame(totals_height, self.values_dict["totals_frame_color"]) # EXP --- # Secondary cart additions # self.secondary_cart_items_frame = self.add_secondary_cart_frame(cart_items_height, self.values_dict["cart_items_frame_color"]) # self.secondary_totals_frame = self.add_secondary_cart_frame(totals_height, "gray") # EXP --- #self.update_admin_frame() self.update_category_frame() self.update_products_frame() self.update_cart() self.update_payment_frame() self.update_debug_frame()
max_trans_number = max_transaction_number_row[0] if max_trans_number is None: max_trans_number = 1 else: return max_trans_number + 1 try: init_file_name = "settings.txt" init_file = open(init_file_name) except: print "Couldn't open settings.txt" values_dict = ReadSettings.get_values_from_init_file(init_file) try: cursor, conn = DatabaseConnect.connect(values_dict) except: print "Error connecting to database" # Insert into database for f in os.listdir("UnsavedTrans"): max_trans_num = get_max_transaction_number(cursor) file_path = os.getcwd() + "/UnsavedTrans/" + f open_f = open(file_path) transaction_statements = open_f.read() open_f.close() clean_statements = transaction_statements.replace("-1,", str(max_trans_num) + ",") print clean_statements for l in clean_statements.split("\n"): cursor.execute(l) conn.commit() os.remove(file_path)
Data written Database connection closed. [('192.168.1.121', '255.255.255.0', 'video', 250.0, 1.5), ('192.168.1.122', '255.255.255.1', 'blog', 55.0, 12.5), ('192.168.1.123', '255.255.255.2', 'video', 356.0, 15.5), ('192.168.1.124', '255.255.255.3', 'music', 157.0, 17.5), ('192.168.1.125', '255.255.255.4', 'other', 58.0, 15.5), ('192.168.1.126', '255.255.255.5', 'other', 9.0, 12.5), ('202.163.1.248', '255.255.244.5', 'other', 9.0, 12.5), ('155.163.5.155', '255.255.255.5', 'other', 9.0, 12.5)] ''' import DatabaseConnect as dc database = dc.DatabaseConnect() print("hello") database.connect() print(database.getTableNames()) data_list = [] # key timestamp mackeysrc mackeydst ipkeysrc ipkeydst bits, channel flags(pass, 2.4, ofdm, cck, gfsk, 5ghz, gsm, cckofdm) #pkts, avg sig str, avg data rate, duration(us), preamble(us), counter b, counter g, counter, n, channel# data_list.append((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24)) data_list.append((2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)) print(len(data_list)) #database.writeDataTable() #database.writeIPData((6, "1.1.1.6")) database.writeData(data_list)
density_goingToSM = 0 density_goingToCalmar = 0 timeNow = int(time.time()) dateTime = str( datetime.datetime.fromtimestamp(timeNow).strftime('%Y-%m-%d %H:%M:%S')) def nothing(): pass vc = cv2.VideoCapture( 'YOUR VIDEO FILENAME HERE SHOULD BE IN THE CURRENT FOLDER.avi') db.create_table1_trafficRecordToSM() db.create_table1_trafficRecordToCalmar() db.create_table2_trafficDataToSM() db.create_table2_trafficDataToCalmar() def computation(): global inCount_goingToSM global inCount_goingToCalmar global inAllSpeeds_goingToSM global inAllSpeeds_goingToCalmar try: avgSpeed_goingToSM = inAllSpeeds_goingToSM / inCount_goingToSM avgSpeed_goingToCalmar = inAllSpeeds_goingToCalmar / inCount_goingToCalmar