Python and YAML. Task: The task is to read and analyze the YAML file using Python, extract the data for inheritance and
Posted: Fri Jul 08, 2022 6:38 am
Python and YAML.
Task: The task is to read and analyze the YAML file usingPython, extract the data for inheritance and abstraction and designit into 2 files: Python Class file and SQL file.
Input will be modeling file in YAML language with dataspecifications. This data needs to be design in such a way toserialize into database by generating SQL queries for creatingtable.
Output should generate two files automatically after executionof main file.
1. First file should be new Class file written in Python code,which should contains Python classes of every entity (or) everydocument in YAML file whether its abstract or not.These classes should have init method and setter-getter method ofattributes as listed in YAML file.If the class has super class, we need to extend the class with thatsuperclass. And the attributes of superclass must be included insubclass.Ex. class Track(FIA):""" Track Description """def __init__(self,data): self.dist = data.get("Distance")self.lapt = data.get("LapTime") // and attributes of superclassreturndef setDistance(self,val): self.dist=valdef getDistance(self): return self.dist
2. Second file should be SQL file, which should contains SQLqueries of CREATE statements for creating tables in database.We need to create tables for non-abstract classes (ie. Concreteclasses).Concrete classes should have its own attributes and inherit theattributes from super classes.The data from YAML file is provided with tablespecifications.Table name should be name mentioned in modeling file, and itsattributes will be the columns of table.Not null, primary key specifications are listed in modeling file.These specifications should be mentioned clearly in Querylanguage.Ex. CREATE TABLE Track ( dist NUMBER(5), lapt NUMBER(10) ); // andattributes of super class
Class properties like name, desc, is_abstract, superclass,tablename, attributes, primary key should be declare seperately, sothat retrieving each variable should be easy.Attributes then again should be specified by apiname, dbname,datatype, size, not_null, is_abstract, modify_values,add_values.
Specifications of attributes, tables, fields, class_propertiesshould be declared carefully in main file so that the main file canbe used for any YAML modeling file.Write two methods for writing each file, writePythonFile andwriteSQLFile.
YAML file:
ModelF1 - Notepad File Edit Format View Help #Model data in YAML name : FIA desc Federation International of Automobile abstract: True attributes : name desc apiname Team datatype: string size: 10 - apiname Sponsor datatype: string size: 100 primary_key: [ Team ] abstract attributes: - dbname : Mercedes : Mercedes AMG Petronas F1 Team : True datatype - dbname datatvne : driver1 : int : driver2 : int
ModelF1 Notepad File Edit Format View Help abstract : True attributes: : driver1 : int : driver2 datatype : int apiname : Chief datatype : string nonnull : True is_abstract: True name desc - dbname datatype - dbname apiname datatype : time nonnull : True is_abstract: True : LapTime - apiname : Chassis datatype : String nonnull : True is_abstract: True primary_key: [ driver1, driver2 ] : W13 : 2022 version F1
ModelF1 - Notepad File Edit Format View Help primary_key: [ driver1 driver2 ] name desc : W13 : 2022 version F1 : W13 tablename superclass : Mercedes, FIA attributes : - apiname : PowerUnit dbname datatype size - apiname dbname datatype size > tablename: track superclass: FIA attributes: : pwru string : 4 : DriverNumber : dnum int : 2 name Track desc Track description
peeee ModelF1 Notepad File Edit Format View Help size : 2 name : Track desc Track description tablename: track superclass: FIA attributes: values: apiname Distance dbname: dist datatype: int size: 5 apiname LapTime dbname lapt datatype time (S1, sector1 ) (S2 sector2 ) (S3, sector3 ) 3 modify_values: False add_values True
Task: The task is to read and analyze the YAML file usingPython, extract the data for inheritance and abstraction and designit into 2 files: Python Class file and SQL file.
Input will be modeling file in YAML language with dataspecifications. This data needs to be design in such a way toserialize into database by generating SQL queries for creatingtable.
Output should generate two files automatically after executionof main file.
1. First file should be new Class file written in Python code,which should contains Python classes of every entity (or) everydocument in YAML file whether its abstract or not.These classes should have init method and setter-getter method ofattributes as listed in YAML file.If the class has super class, we need to extend the class with thatsuperclass. And the attributes of superclass must be included insubclass.Ex. class Track(FIA):""" Track Description """def __init__(self,data): self.dist = data.get("Distance")self.lapt = data.get("LapTime") // and attributes of superclassreturndef setDistance(self,val): self.dist=valdef getDistance(self): return self.dist
2. Second file should be SQL file, which should contains SQLqueries of CREATE statements for creating tables in database.We need to create tables for non-abstract classes (ie. Concreteclasses).Concrete classes should have its own attributes and inherit theattributes from super classes.The data from YAML file is provided with tablespecifications.Table name should be name mentioned in modeling file, and itsattributes will be the columns of table.Not null, primary key specifications are listed in modeling file.These specifications should be mentioned clearly in Querylanguage.Ex. CREATE TABLE Track ( dist NUMBER(5), lapt NUMBER(10) ); // andattributes of super class
Class properties like name, desc, is_abstract, superclass,tablename, attributes, primary key should be declare seperately, sothat retrieving each variable should be easy.Attributes then again should be specified by apiname, dbname,datatype, size, not_null, is_abstract, modify_values,add_values.
Specifications of attributes, tables, fields, class_propertiesshould be declared carefully in main file so that the main file canbe used for any YAML modeling file.Write two methods for writing each file, writePythonFile andwriteSQLFile.
YAML file:
ModelF1 - Notepad File Edit Format View Help #Model data in YAML name : FIA desc Federation International of Automobile abstract: True attributes : name desc apiname Team datatype: string size: 10 - apiname Sponsor datatype: string size: 100 primary_key: [ Team ] abstract attributes: - dbname : Mercedes : Mercedes AMG Petronas F1 Team : True datatype - dbname datatvne : driver1 : int : driver2 : int
ModelF1 Notepad File Edit Format View Help abstract : True attributes: : driver1 : int : driver2 datatype : int apiname : Chief datatype : string nonnull : True is_abstract: True name desc - dbname datatype - dbname apiname datatype : time nonnull : True is_abstract: True : LapTime - apiname : Chassis datatype : String nonnull : True is_abstract: True primary_key: [ driver1, driver2 ] : W13 : 2022 version F1
ModelF1 - Notepad File Edit Format View Help primary_key: [ driver1 driver2 ] name desc : W13 : 2022 version F1 : W13 tablename superclass : Mercedes, FIA attributes : - apiname : PowerUnit dbname datatype size - apiname dbname datatype size > tablename: track superclass: FIA attributes: : pwru string : 4 : DriverNumber : dnum int : 2 name Track desc Track description
peeee ModelF1 Notepad File Edit Format View Help size : 2 name : Track desc Track description tablename: track superclass: FIA attributes: values: apiname Distance dbname: dist datatype: int size: 5 apiname LapTime dbname lapt datatype time (S1, sector1 ) (S2 sector2 ) (S3, sector3 ) 3 modify_values: False add_values True