def afficherTable(self, table): """ display all elements of equipment """ to_return = "table " + str(table) to_return = to_return + "<table border=\"1\"> " nbrColumns = 0 to_return = to_return + "<tr>" for field in db.get_name_of_column_in_array(pathDataBase, str(table)): to_return = to_return + "<td>" + field + "</td>" nbrColumns = nbrColumns + 1 to_return = to_return + "</tr>" tmp = 0 for elem in db.get_all_element_of_table(pathDataBase, str(table)): if tmp == 0: to_return = to_return + "<tr>" to_return = to_return + "<td>" + str(elem) + "</td>" if tmp == nbrColumns - 1: to_return = to_return + "<tr>" tmp = -1 tmp = tmp + 1 return to_return + "</table>" + "<a href=\"index\">return to index<a>"
def putLFNS( self, lfns ): lfnList=list() db = DataBase() db.createTables() for lfn in lfns : res = db.putLFN( str( lfn ) ) lfnList.append( res ) return S_OK( lfnList )
def insertSequence( self, sequence ): """ insert in bloc into database a sequence of operation""" db = DataBase() db.createTables() res = db.putSequence( sequence ) if not res["OK"]: gLogger.error( ' error' , res['Message'] ) exit() return res
class ServerHandler: def __init__(self): self.log = {} self.db = DataBase() def deleteChapter(self, name): print("getConstants()") self.db.deleteChapter(name) def getChapter(self): return self.db.getChapterName() def getFullText(self, chapter): print("getFullText()") return self.db.getFullText(chapter)
def search(self, table, toSearch, field): """ display elements in table where field in data base contain toSearch """ to_return = "" to_return = to_return + "<table border=\"1\"> " to_return = to_return + "<tr>" for element in db.get_name_of_column_in_array(pathDataBase, str(table)): to_return = to_return + "<td>" + element + "</td>" to_return = to_return + "</tr>" to_return = to_return + db.search_element_of_table( pathDataBase, str(table), field, str(toSearch)) to_return = to_return + "</table>" return to_return + "<a href=\"index\">return to index<a>"
def join(self, table1, table2, field1, field2, search1, search2): to_return = "" for row in db.jointure_table(pathDataBase, table1, table2, field1, field2, search1, search2): to_return = to_return + "</br>" + str(row) if to_return != "": return to_return + "</br><a href=\"index\">return to index<a>" else: return "nothing found" + "</br><a href=\"index\">return to index<a>"
def main(argv=None): db = DataBase(whichfold=FLAGS.fold) cfg = EvalModelConfig(FLAGS.fold) eval_dir = cfg.get_current_eval_dir() if tf.gfile.Exists(eval_dir): tf.gfile.DeleteRecursively(eval_dir) tf.gfile.MakeDirs(eval_dir) evaluate(inference, cfg, db)
def __init__(self, db_file): self.db = DB(db_file) self.Material_Map = None query1 = "SELECT * FROM Cust_Order ORDER BY Order_Week ASC" query2 = "SELECT * FROM schedule_receipt" self.Order_Table = self.db.run_select_query(query1) self.last_order = self.Order_Table[-1][-1] self.Schedule_Receipt_Table = self.db.run_select_query(query2)
def main(argv=None): # pylint: disable=unused-argument db = DataBase(whichfold=FLAGS.fold) cfg = ModelConfig(whichfold=FLAGS.fold) train_dir = cfg.get_current_model_dir() IF_CONTINUE_TRAIN = cfg.IF_CONTINUE == 1 if (not IF_CONTINUE_TRAIN) and tf.gfile.Exists(train_dir): tf.gfile.DeleteRecursively(train_dir) tf.gfile.MakeDirs(train_dir) screen_train(inference, getloss, cfg, db)
def SQL(self, query): """ display interface for make query and display the result """ to_return = """ <form method="get" action="SQL"> make query: </br> <TEXTAREA name="query"></TEXTAREA> </br> <input type="submit"> </form> """ if (str(query) != "init"): to_return = to_return + "result of the query: </br><div style=\"background: #AAAAAA\">" result = "" for elem in db.make_query(pathDataBase, query): result = result + str(elem) result = result + "</br>" to_return = to_return + result + "</div>" return to_return + "<a href=\"index\">return to index<a>"
'''Created by Chen Yizhi in 2017. ''' import sys import os sys.path.append(os.getcwd() + "/..") import screen_volume from train import ModelConfig from network import inference from dataBase import DataBase import argparse parser = argparse.ArgumentParser() parser.add_argument("--fold", type=int, help='which cross validation fold') FLAGS = parser.parse_args() os.environ["CUDA_VISIBLE_DEVICES"] = "0" if __name__ == '__main__': cfg = ModelConfig(FLAGS.fold) db = DataBase(FLAGS.fold) cfg.multi_flag = [1, 0] print('multi_flag: ', cfg.multi_flag) cfg.result_file_fold = str(cfg.cross_index) screen_volume.screen_cnn(inference, db, cfg) screen_volume.analysis_of_screen(db, cfg, 0.999, 0.5) #screen_volume.produce_tf_samples(volume_manager, multi_flag, result_file_fold)
class App(): def __init__(self, db_file): self.db = DB(db_file) self.Material_Map = None query1 = "SELECT * FROM Cust_Order ORDER BY Order_Week ASC" query2 = "SELECT * FROM schedule_receipt" self.Order_Table = self.db.run_select_query(query1) self.last_order = self.Order_Table[-1][-1] self.Schedule_Receipt_Table = self.db.run_select_query(query2) def start(self): self.set_bom() self.initialize_table(self.last_order) for i, order in enumerate(self.Order_Table): self.calculate_MRP(order, i) keys = self.Material_Map.keys() for key in keys: self.recordMRP(self.Material_Map[str(key)]) def recordMRP(self, table): #query_deletion = """Delete from 'MRP_Data' """ #self.db.run_select_query(query_deletion) query = """insert Into MRP_Data (Week, Material_ID, Gross_Req, Schedule_recipt, Proj_Balance,\ Net_Req, Plan_Order, Plan_Release, Inventory_Level) values """ rng = len(table.demand) tmp = [] for i in range(1, rng): tmp_str = """( %s, %s, %s, %s, %s, %s, %s, %s, %s) """ % ( i, table.id, table.demand[i], table.scheduled_rec[i], table.proj_balance[i], table.net_req[i], table.release[i], table.planned_rec[i], table.inventory[i]) tmp.append(tmp_str) query = query + ',\n'.join(tmp) self.db.run_insert_query(query) def set_bom(self): query = "SELECT * FROM BOM" query2 = "SELECT * FROM Material" BOM_Table = self.db.run_select_query(query) Material_Table = self.db.run_select_query(query2) table_map = {} for i, row in enumerate(Material_Table): m_id, m_name, _, m_lead, m_batch = row table_map[str(m_id)] = Table(m_id, m_name, m_lead, m_batch) if i == 0: table_map[str(m_id)].isRoot = True keys = table_map.keys() for table_id in keys: for j, BOMrow in enumerate(BOM_Table): if int(table_id) == BOMrow[0]: piece_id = BOMrow[1] piece = table_map[str(piece_id)] subpart_quantity = BOMrow[2] piece.ingredientOf.append(table_map[table_id]) table_map[table_id].children.append( (piece, subpart_quantity)) self.Material_Map = table_map def calculate_MRP(self, order, counter): _, ordered_partID, demand, delivery_week = order ordered_material = self.Material_Map[str(ordered_partID)] start_week = 0 end_week = delivery_week + 1 if counter == 0: start_week = 1 else: start_week = self.Order_Table[counter - 1][-1] self.inv_check(start_week + 1, end_week, ordered_material) net_req = max( 0, demand - ordered_material.scheduled_rec[delivery_week] - ordered_material.inventory[delivery_week] + ordered_material.proj_balance[delivery_week]) planned_rec = ordered_material.batch_size * (math.ceil( net_req / ordered_material.batch_size)) ordered_material.demand[delivery_week] += demand ordered_material.net_req[delivery_week] += net_req if net_req > 0: deadline = delivery_week - ordered_material.lead_time if net_req > 0 and deadline < 1: print( "[Warning!] Deadline week is a negative value. It cannot be calculated." ) exit(1) ordered_material.planned_rec[delivery_week] += planned_rec ordered_material.inventory[delivery_week + 1] += planned_rec - net_req ordered_material.release[deadline] += planned_rec if deadline > 0: self.calculate_for_pieces(ordered_material, deadline, 0) def calculate_for_pieces(self, ingredientOfTable, deadline_from_ingredientOf, counter): amount_of_children = len(ingredientOfTable.children) if amount_of_children == 0: return for tpl in ingredientOfTable.children: piece, quantity = tpl deadline_for_piece = deadline_from_ingredientOf - piece.lead_time start_week = 1 end_week = deadline_from_ingredientOf + 1 for i, value in reversed(list(enumerate(piece.demand))): if value != 0: start_week = i + 1 break self.inv_check(start_week, end_week, piece) demand = ingredientOfTable.release[ deadline_from_ingredientOf] * quantity net_req = demand - piece.scheduled_rec[ deadline_from_ingredientOf] + piece.proj_balance[ deadline_from_ingredientOf] - piece.inventory[ deadline_from_ingredientOf] planned_rec = piece.batch_size * (math.ceil( net_req / piece.batch_size)) if net_req > 0 and deadline_for_piece < 1: print( "[Warning!] Deadline week is a negative value. It cannot be calculated." ) exit(1) piece.demand[deadline_from_ingredientOf] += demand piece.net_req[deadline_from_ingredientOf] += net_req piece.planned_rec[deadline_from_ingredientOf] += planned_rec piece.release[deadline_for_piece] += planned_rec piece.inventory[deadline_from_ingredientOf + 1] += planned_rec - net_req self.calculate_for_pieces(piece, deadline_for_piece, 0) def initialize_table(self, rng): keys = self.Material_Map.keys() mrp_period = len(self.Material_Map['1'].demand) tmp = None flag = False if mrp_period == 0: tmp = [0 for j in range(rng + 2)] flag = True else: additionZeros = rng + 2 - mrp_period tmp = [0 for j in range(additionZeros)] for i in keys: self.Material_Map[i].demand.extend(tmp) self.Material_Map[i].scheduled_rec.extend(tmp) self.Material_Map[i].proj_balance.extend(tmp) self.Material_Map[i].net_req.extend(tmp) self.Material_Map[i].planned_rec.extend(tmp) self.Material_Map[i].release.extend(tmp) self.Material_Map[i].inventory.extend(tmp) if flag: self.set_scheduledRec_values_for_mrp_table() def inv_check(self, start_week, end_week, Table): for i in range(start_week, end_week): if (Table.demand[i - 1] - Table.scheduled_rec[i - 1] - Table.inventory[i - 1] + Table.proj_balance[i - 1]) < 0: Table.inventory[i] += -1 * ( Table.demand[i - 1] - Table.scheduled_rec[i - 1] - Table.inventory[i - 1] + Table.proj_balance[i - 1]) def get_total_lead_time(self, Table): total_lt = Table.lead_time while len(Table.ingredientOf) != 0: Table = Table.ingredientOf[0] total_lt += Table.lead_time return total_lt def set_scheduledRec_values_for_mrp_table(self): for row in self.Schedule_Receipt_Table: _, material_id, quantity, weekIndex = row self.Material_Map[str(material_id)].scheduled_rec[weekIndex - 1] = quantity
def __init__(self): self.log = {} self.db = DataBase()
def searchOption(self): """ display form for search elements in data base """ to_return = "" to_return = to_return + """ <h1>Search something</h1> <h2>search in tables: </h2> <table border=\"10\"> <form method="get" action="search"> <tr> <td> <p name="table" value="Equipment">Equipment</p> </td> <td> <input type="text" name="toSearch"> </td> <td> <select name="field" id="searchEquipment"> """ for field in db.get_name_of_column_in_array(pathDataBase, "Equipment"): to_return = to_return + "<option value=" + str(field) + ">" + str( field) + "</option>" to_return = to_return + """ </select> </td> <td> <input type="submit"> </td> </tr> <input style="display: none" name="table" value="Equipment"> </form> <form method="get" action="search" > <tr> <td> Activity </td> <td> <input type="text" name="toSearch"> </td> <td> <select name="field" id="searchActivity"> """ for field in db.get_name_of_column_in_array(pathDataBase, "Activity"): to_return = to_return + "<option value=" + str(field) + ">" + str( field) + "</option>" to_return = to_return + """ </select> </td> <td> <input type="submit"> </td> </tr> <input style="display: none" name="table" value="Activity"> </form> <form method="get" action="search"> <tr> <td> Installations </td> <td> <input type="text" name="toSearch"> </td> <td> <select name="field" id="searchInstallation"> """ for field in db.get_name_of_column_in_array(pathDataBase, "Installations"): to_return = to_return + "<option value=" + str(field) + ">" + str( field) + "</option>" to_return = to_return + """ </select> </td> <td> <input type="submit"> </td> </tr> <input style="display: none" name="table" value="Installations"> </form> </table> """ to_return = to_return + """ <h2>join tables 1 with table 2:</h2> <script> function actualiserField1(){ var table1 = document.getElementById("table1"); tableSelected = table1.options[table1.selectedIndex].value; if(tableSelected == "Equipment") document.getElementById("field1").innerHTML = document.getElementById("searchEquipment").innerHTML; if(tableSelected == "Activity") document.getElementById("field1").innerHTML = document.getElementById("searchActivity").innerHTML; if(tableSelected == "Installations") document.getElementById("field1").innerHTML = document.getElementById("searchInstallation").innerHTML; } function actualiserField2(){ var table1 = document.getElementById("table2"); tableSelected = table1.options[table1.selectedIndex].value; if(tableSelected == "Equipment") document.getElementById("field2").innerHTML = document.getElementById("searchEquipment").innerHTML; if(tableSelected == "Activity") document.getElementById("field2").innerHTML = document.getElementById("searchActivity").innerHTML; if(tableSelected == "Installations") document.getElementById("field2").innerHTML = document.getElementById("searchInstallation").innerHTML; } </script> <form method="get" action="join"> <table border=\"10\"> <tr> <td>num tab</td> <td>table</td> <td>field</td> <td>elements to search</td> </tr> <tr> <td>1</td> <td> <select name="table1" id="table1"> <option value=\"Activity\" selected onclick="actualiserField1()">Activity</option> <option value=\"Equipment\" onclick="actualiserField1()">Equipment</option> <option value=\"Installations\" onclick="actualiserField1()">Installations</option> </select> </td> <td> <select name="field1" id="field1"> <option selected onclick="actualiserField1()">click to refresh</option> </select> </td> <td> <input type=\"text\" name="search1"/> </td> </tr> <tr> <td>2</td> <td> <select name="table2" id="table2"> <option value=\"Activity\" selected onclick="actualiserField2()">Activity</option> <option value=\"Equipment\" onclick="actualiserField2()">Equipment</option> <option value=\"Installations\" onclick="actualiserField2()">Installations</option> </select> </td> <td> <select name="field2" id="field2"> <option selected onload="actualiserField2()">click to refresh</option> </select> </td> <td> <input type=\"text\" name="search2"/> </td> </tr> </table> <input type=\"submit\" /> </form> e.g with <table border="10"> <tr> <td>Installations</td> <td>nameTown</td> <td>Nantes</td> </tr> <tr> <td>Activity</td> <td>actLib</td> <td>Football</td> </tr> </table> <script>actualiserField1();actualiserField2();</script> """ return to_return + "</br><a href=\"index\">return to index<a>"
from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_bcrypt import Bcrypt from flask_login import LoginManager from dataBase import DataBase from person import Person app = Flask(__name__) app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245' app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' db = SQLAlchemy(app) bcrypt = Bcrypt(app) login_manager = LoginManager(app) login_manager.login_view = 'login' login_manager.login_message_category = 'info' database = DataBase('datbase.json') from flaskblog import routes
action='store_true', help='set optional json file ') parser.add_argument('-act_json', '--activity_json', action='store_true', help='set optional json file ') parser.add_argument('-equ_json', '--equipments_json', action='store_true', help='set optional json file ') args = parser.parse_args() path_data_base = args.path_data_base DataBase.init_data_base_installation(path_data_base) DataBase.init_data_base_activity(path_data_base) DataBase.init_data_base_equipment(path_data_base) if args.installations_json: path_installations_json = input( 'Enter the path of json file installations:') print("unserialise json installations and import to data base ...") installationArray = Serializer.unserialise_installations_json( path_installations_json) Serializer.object_export_in_dataBase(installationArray, path_data_base) if args.activity_json: path_activity_json = input('Enter the path of json file activity:')
def __init__(self, iface): DataBase.__init__(self) self.iface = iface