11758Ssaidi@eecs.umich.edu# Copyright (c) 2003-2004 The Regents of The University of Michigan 21758Ssaidi@eecs.umich.edu# All rights reserved. 31758Ssaidi@eecs.umich.edu# 41758Ssaidi@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 51758Ssaidi@eecs.umich.edu# modification, are permitted provided that the following conditions are 61758Ssaidi@eecs.umich.edu# met: redistributions of source code must retain the above copyright 71758Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 81758Ssaidi@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 91758Ssaidi@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 101758Ssaidi@eecs.umich.edu# documentation and/or other materials provided with the distribution; 111758Ssaidi@eecs.umich.edu# neither the name of the copyright holders nor the names of its 121758Ssaidi@eecs.umich.edu# contributors may be used to endorse or promote products derived from 131758Ssaidi@eecs.umich.edu# this software without specific prior written permission. 141758Ssaidi@eecs.umich.edu# 151758Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161758Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171758Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 181758Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 191758Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 201758Ssaidi@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 211758Ssaidi@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221758Ssaidi@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231758Ssaidi@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241758Ssaidi@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 251758Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262665Ssaidi@eecs.umich.edu# 272665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert 281758Ssaidi@eecs.umich.edu 291049Sbinkertn@umich.eduimport MySQLdb 301049Sbinkertn@umich.edu 311049Sbinkertn@umich.educlass MyDB(object): 321049Sbinkertn@umich.edu def __init__(self, options): 331049Sbinkertn@umich.edu self.name = options.db 341049Sbinkertn@umich.edu self.host = options.host 351049Sbinkertn@umich.edu self.user = options.user 361049Sbinkertn@umich.edu self.passwd = options.passwd 371049Sbinkertn@umich.edu self.mydb = None 381049Sbinkertn@umich.edu self.cursor = None 391049Sbinkertn@umich.edu 401049Sbinkertn@umich.edu def admin(self): 411049Sbinkertn@umich.edu self.close() 421049Sbinkertn@umich.edu self.mydb = MySQLdb.connect(db='mysql', host=self.host, user=self.user, 431049Sbinkertn@umich.edu passwd=self.passwd) 441049Sbinkertn@umich.edu self.cursor = self.mydb.cursor() 451049Sbinkertn@umich.edu 461049Sbinkertn@umich.edu def connect(self): 471049Sbinkertn@umich.edu self.close() 481049Sbinkertn@umich.edu self.mydb = MySQLdb.connect(db=self.name, host=self.host, 491049Sbinkertn@umich.edu user=self.user, passwd=self.passwd) 501049Sbinkertn@umich.edu self.cursor = self.mydb.cursor() 511049Sbinkertn@umich.edu 521049Sbinkertn@umich.edu def close(self): 531049Sbinkertn@umich.edu if self.mydb is not None: 541049Sbinkertn@umich.edu self.mydb.close() 551049Sbinkertn@umich.edu self.cursor = None 561049Sbinkertn@umich.edu 571049Sbinkertn@umich.edu def query(self, sql): 581049Sbinkertn@umich.edu self.cursor.execute(sql) 591049Sbinkertn@umich.edu 601049Sbinkertn@umich.edu def drop(self): 611049Sbinkertn@umich.edu self.query('DROP DATABASE IF EXISTS %s' % self.name) 621049Sbinkertn@umich.edu 631049Sbinkertn@umich.edu def create(self): 641049Sbinkertn@umich.edu self.query('CREATE DATABASE %s' % self.name) 651049Sbinkertn@umich.edu 661049Sbinkertn@umich.edu def populate(self): 671049Sbinkertn@umich.edu # 681049Sbinkertn@umich.edu # Each run (or simulation) gets its own entry in the runs table to 691049Sbinkertn@umich.edu # group stats by where they were generated 701049Sbinkertn@umich.edu # 711049Sbinkertn@umich.edu # COLUMNS: 721049Sbinkertn@umich.edu # 'id' is a unique identifier for each run to be used in other 731049Sbinkertn@umich.edu # tables. 741049Sbinkertn@umich.edu # 'name' is the user designated name for the data generated. It is 751049Sbinkertn@umich.edu # configured in the simulator. 761049Sbinkertn@umich.edu # 'user' identifies the user that generated the data for the given 771049Sbinkertn@umich.edu # run. 781049Sbinkertn@umich.edu # 'project' another name to identify runs for a specific goal 791049Sbinkertn@umich.edu # 'date' is a timestamp for when the data was generated. It can be 801049Sbinkertn@umich.edu # used to easily expire data that was generated in the past. 811049Sbinkertn@umich.edu # 'expire' is a timestamp for when the data should be removed from 821049Sbinkertn@umich.edu # the database so we don't have years worth of junk. 831049Sbinkertn@umich.edu # 841049Sbinkertn@umich.edu # INDEXES: 851049Sbinkertn@umich.edu # 'run' is indexed so you can find out details of a run if the run 861049Sbinkertn@umich.edu # was retreived from the data table. 871049Sbinkertn@umich.edu # 'name' is indexed so that two all run names are forced to be unique 881049Sbinkertn@umich.edu # 891049Sbinkertn@umich.edu self.query(''' 901049Sbinkertn@umich.edu CREATE TABLE runs( 911049Sbinkertn@umich.edu rn_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, 921049Sbinkertn@umich.edu rn_name VARCHAR(200) NOT NULL, 931049Sbinkertn@umich.edu rn_sample VARCHAR(32) NOT NULL, 941049Sbinkertn@umich.edu rn_user VARCHAR(32) NOT NULL, 951049Sbinkertn@umich.edu rn_project VARCHAR(100) NOT NULL, 961049Sbinkertn@umich.edu rn_date TIMESTAMP NOT NULL, 971049Sbinkertn@umich.edu rn_expire TIMESTAMP NOT NULL, 981049Sbinkertn@umich.edu PRIMARY KEY (rn_id), 991049Sbinkertn@umich.edu UNIQUE (rn_name,rn_sample) 1001049Sbinkertn@umich.edu ) TYPE=InnoDB''') 1011049Sbinkertn@umich.edu 1021049Sbinkertn@umich.edu # 1031049Sbinkertn@umich.edu # The stat table gives us all of the data for a particular stat. 1041049Sbinkertn@umich.edu # 1051049Sbinkertn@umich.edu # COLUMNS: 1061049Sbinkertn@umich.edu # 'stat' is a unique identifier for each stat to be used in other 1071049Sbinkertn@umich.edu # tables for references. 1081049Sbinkertn@umich.edu # 'name' is simply the simulator derived name for a given 1091049Sbinkertn@umich.edu # statistic. 1101049Sbinkertn@umich.edu # 'descr' is the description of the statistic and what it tells 1111049Sbinkertn@umich.edu # you. 1121049Sbinkertn@umich.edu # 'type' defines what the stat tells you. Types are: 1131049Sbinkertn@umich.edu # SCALAR: A simple scalar statistic that holds one value 1141049Sbinkertn@umich.edu # VECTOR: An array of statistic values. Such a something that 1151049Sbinkertn@umich.edu # is generated per-thread. Vectors exist to give averages, 1161049Sbinkertn@umich.edu # pdfs, cdfs, means, standard deviations, etc across the 1171049Sbinkertn@umich.edu # stat values. 1181049Sbinkertn@umich.edu # DIST: Is a distribution of data. When the statistic value is 1191049Sbinkertn@umich.edu # sampled, its value is counted in a particular bucket. 1201049Sbinkertn@umich.edu # Useful for keeping track of utilization of a resource. 1211049Sbinkertn@umich.edu # (e.g. fraction of time it is 25% used vs. 50% vs. 100%) 1221049Sbinkertn@umich.edu # VECTORDIST: Can be used when the distribution needs to be 1231049Sbinkertn@umich.edu # factored out into a per-thread distribution of data for 1241049Sbinkertn@umich.edu # example. It can still be summed across threads to find 1251049Sbinkertn@umich.edu # the total distribution. 1261049Sbinkertn@umich.edu # VECTOR2D: Can be used when you have a stat that is not only 1271049Sbinkertn@umich.edu # per-thread, but it is per-something else. Like 1281049Sbinkertn@umich.edu # per-message type. 1291049Sbinkertn@umich.edu # FORMULA: This statistic is a formula, and its data must be 1301049Sbinkertn@umich.edu # looked up in the formula table, for indicating how to 1311049Sbinkertn@umich.edu # present its values. 1321049Sbinkertn@umich.edu # 'subdata' is potentially used by any of the vector types to 1331049Sbinkertn@umich.edu # give a specific name to all of the data elements within a 1341049Sbinkertn@umich.edu # stat. 1351049Sbinkertn@umich.edu # 'print' indicates whether this stat should be printed ever. 1361049Sbinkertn@umich.edu # (Unnamed stats don't usually get printed) 1371049Sbinkertn@umich.edu # 'prereq' only print the stat if the prereq is not zero. 1381049Sbinkertn@umich.edu # 'prec' number of decimal places to print 1391049Sbinkertn@umich.edu # 'nozero' don't print zero values 1401049Sbinkertn@umich.edu # 'nonan' don't print NaN values 1411049Sbinkertn@umich.edu # 'total' for vector type stats, print the total. 1421049Sbinkertn@umich.edu # 'pdf' for vector type stats, print the pdf. 1431049Sbinkertn@umich.edu # 'cdf' for vector type stats, print the cdf. 1441049Sbinkertn@umich.edu # 1451049Sbinkertn@umich.edu # The Following are for dist type stats: 1461049Sbinkertn@umich.edu # 'min' is the minimum bucket value. Anything less is an underflow. 1471049Sbinkertn@umich.edu # 'max' is the maximum bucket value. Anything more is an overflow. 1481049Sbinkertn@umich.edu # 'bktsize' is the approximate number of entries in each bucket. 1491049Sbinkertn@umich.edu # 'size' is the number of buckets. equal to (min/max)/bktsize. 1501049Sbinkertn@umich.edu # 1511049Sbinkertn@umich.edu # INDEXES: 1521049Sbinkertn@umich.edu # 'stat' is indexed so that you can find out details about a stat 1531049Sbinkertn@umich.edu # if the stat id was retrieved from the data table. 1541049Sbinkertn@umich.edu # 'name' is indexed so that you can simply look up data about a 1551049Sbinkertn@umich.edu # named stat. 1561049Sbinkertn@umich.edu # 1571049Sbinkertn@umich.edu self.query(''' 1581049Sbinkertn@umich.edu CREATE TABLE stats( 1591049Sbinkertn@umich.edu st_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, 1601049Sbinkertn@umich.edu st_name VARCHAR(255) NOT NULL, 1611049Sbinkertn@umich.edu st_descr TEXT NOT NULL, 1621049Sbinkertn@umich.edu st_type ENUM("SCALAR", "VECTOR", "DIST", "VECTORDIST", 1631049Sbinkertn@umich.edu "VECTOR2D", "FORMULA") NOT NULL, 1641049Sbinkertn@umich.edu st_print BOOL NOT NULL, 1651049Sbinkertn@umich.edu st_prereq SMALLINT UNSIGNED NOT NULL, 1661049Sbinkertn@umich.edu st_prec TINYINT NOT NULL, 1671049Sbinkertn@umich.edu st_nozero BOOL NOT NULL, 1681049Sbinkertn@umich.edu st_nonan BOOL NOT NULL, 1691049Sbinkertn@umich.edu st_total BOOL NOT NULL, 1701049Sbinkertn@umich.edu st_pdf BOOL NOT NULL, 1711049Sbinkertn@umich.edu st_cdf BOOL NOT NULL, 1721049Sbinkertn@umich.edu st_min DOUBLE NOT NULL, 1731049Sbinkertn@umich.edu st_max DOUBLE NOT NULL, 1741049Sbinkertn@umich.edu st_bktsize DOUBLE NOT NULL, 1751049Sbinkertn@umich.edu st_size SMALLINT UNSIGNED NOT NULL, 1761049Sbinkertn@umich.edu PRIMARY KEY (st_id), 1771049Sbinkertn@umich.edu UNIQUE (st_name) 1781049Sbinkertn@umich.edu ) TYPE=InnoDB''') 1791049Sbinkertn@umich.edu 1801049Sbinkertn@umich.edu # 1811049Sbinkertn@umich.edu # This is the main table of data for stats. 1821049Sbinkertn@umich.edu # 1831049Sbinkertn@umich.edu # COLUMNS: 1841049Sbinkertn@umich.edu # 'stat' refers to the stat field given in the stat table. 1851049Sbinkertn@umich.edu # 1861049Sbinkertn@umich.edu # 'x' referrs to the first dimension of a multi-dimensional stat. For 1871049Sbinkertn@umich.edu # a vector, x will start at 0 and increase for each vector 1881049Sbinkertn@umich.edu # element. 1891049Sbinkertn@umich.edu # For a distribution: 1901049Sbinkertn@umich.edu # -1: sum (for calculating standard deviation) 1911049Sbinkertn@umich.edu # -2: sum of squares (for calculating standard deviation) 1921049Sbinkertn@umich.edu # -3: total number of samples taken (for calculating 1931049Sbinkertn@umich.edu # standard deviation) 1941049Sbinkertn@umich.edu # -4: minimum value 1951049Sbinkertn@umich.edu # -5: maximum value 1961049Sbinkertn@umich.edu # -6: underflow 1971049Sbinkertn@umich.edu # -7: overflow 1981049Sbinkertn@umich.edu # 'y' is used by a VECTORDIST and the VECTOR2D to describe the second 1991049Sbinkertn@umich.edu # dimension. 2001049Sbinkertn@umich.edu # 'run' is the run that the data was generated from. Details up in 2011049Sbinkertn@umich.edu # the run table 2021049Sbinkertn@umich.edu # 'tick' is a timestamp generated by the simulator. 2031049Sbinkertn@umich.edu # 'data' is the actual stat value. 2041049Sbinkertn@umich.edu # 2051049Sbinkertn@umich.edu # INDEXES: 2061049Sbinkertn@umich.edu # 'stat' is indexed so that a user can find all of the data for a 2071049Sbinkertn@umich.edu # particular stat. It is not unique, because that specific stat 2082343Sbinkertn@umich.edu # can be found in many runs and samples, in addition to 2091049Sbinkertn@umich.edu # having entries for the mulidimensional cases. 2101049Sbinkertn@umich.edu # 'run' is indexed to allow a user to remove all of the data for a 2111049Sbinkertn@umich.edu # particular execution run. It can also be used to allow the 2121049Sbinkertn@umich.edu # user to print out all of the data for a given run. 2131049Sbinkertn@umich.edu # 2141049Sbinkertn@umich.edu self.query(''' 2151049Sbinkertn@umich.edu CREATE TABLE data( 2161049Sbinkertn@umich.edu dt_stat SMALLINT UNSIGNED NOT NULL, 2171049Sbinkertn@umich.edu dt_x SMALLINT NOT NULL, 2181049Sbinkertn@umich.edu dt_y SMALLINT NOT NULL, 2191049Sbinkertn@umich.edu dt_run SMALLINT UNSIGNED NOT NULL, 2201049Sbinkertn@umich.edu dt_tick BIGINT UNSIGNED NOT NULL, 2211049Sbinkertn@umich.edu dt_data DOUBLE NOT NULL, 2221049Sbinkertn@umich.edu INDEX (dt_stat), 2231049Sbinkertn@umich.edu INDEX (dt_run), 2242343Sbinkertn@umich.edu UNIQUE (dt_stat,dt_x,dt_y,dt_run,dt_tick) 2251049Sbinkertn@umich.edu ) TYPE=InnoDB;''') 2261049Sbinkertn@umich.edu 2271049Sbinkertn@umich.edu # 2281049Sbinkertn@umich.edu # Names and descriptions for multi-dimensional stats (vectors, etc.) 2291049Sbinkertn@umich.edu # are stored here instead of having their own entry in the statistics 2301049Sbinkertn@umich.edu # table. This allows all parts of a single stat to easily share a 2311049Sbinkertn@umich.edu # single id. 2321049Sbinkertn@umich.edu # 2331049Sbinkertn@umich.edu # COLUMNS: 2341049Sbinkertn@umich.edu # 'stat' is the unique stat identifier from the stat table. 2351049Sbinkertn@umich.edu # 'x' is the first dimension for multi-dimensional stats 2361049Sbinkertn@umich.edu # corresponding to the data table above. 2371049Sbinkertn@umich.edu # 'y' is the second dimension for multi-dimensional stats 2381049Sbinkertn@umich.edu # corresponding to the data table above. 2391049Sbinkertn@umich.edu # 'name' is the specific subname for the unique stat,x,y combination. 2401049Sbinkertn@umich.edu # 'descr' is the specific description for the uniqe stat,x,y 2411049Sbinkertn@umich.edu # combination. 2421049Sbinkertn@umich.edu # 2431049Sbinkertn@umich.edu # INDEXES: 2441049Sbinkertn@umich.edu # 'stat' is indexed so you can get the subdata for a specific stat. 2451049Sbinkertn@umich.edu # 2461049Sbinkertn@umich.edu self.query(''' 2471049Sbinkertn@umich.edu CREATE TABLE subdata( 2481049Sbinkertn@umich.edu sd_stat SMALLINT UNSIGNED NOT NULL, 2491049Sbinkertn@umich.edu sd_x SMALLINT NOT NULL, 2501049Sbinkertn@umich.edu sd_y SMALLINT NOT NULL, 2511049Sbinkertn@umich.edu sd_name VARCHAR(255) NOT NULL, 2521049Sbinkertn@umich.edu sd_descr TEXT, 2531049Sbinkertn@umich.edu UNIQUE (sd_stat,sd_x,sd_y) 2541049Sbinkertn@umich.edu ) TYPE=InnoDB''') 2551049Sbinkertn@umich.edu 2561049Sbinkertn@umich.edu 2571049Sbinkertn@umich.edu # 2581049Sbinkertn@umich.edu # The formula table is maintained separately from the data table 2591049Sbinkertn@umich.edu # because formula data, unlike other stat data cannot be represented 2601049Sbinkertn@umich.edu # there. 2611049Sbinkertn@umich.edu # 2621049Sbinkertn@umich.edu # COLUMNS: 2631049Sbinkertn@umich.edu # 'stat' refers to the stat field generated in the stat table. 2641049Sbinkertn@umich.edu # 'formula' is the actual string representation of the formula 2651049Sbinkertn@umich.edu # itself. 2661049Sbinkertn@umich.edu # 2671049Sbinkertn@umich.edu # INDEXES: 2681049Sbinkertn@umich.edu # 'stat' is indexed so that you can just look up a formula. 2691049Sbinkertn@umich.edu # 2701049Sbinkertn@umich.edu self.query(''' 2711049Sbinkertn@umich.edu CREATE TABLE formulas( 2721049Sbinkertn@umich.edu fm_stat SMALLINT UNSIGNED NOT NULL, 2731049Sbinkertn@umich.edu fm_formula BLOB NOT NULL, 2741049Sbinkertn@umich.edu PRIMARY KEY(fm_stat) 2751049Sbinkertn@umich.edu ) TYPE=InnoDB''') 2761049Sbinkertn@umich.edu 2771049Sbinkertn@umich.edu # 2781049Sbinkertn@umich.edu # Each stat used in each formula is kept in this table. This way, if 2791049Sbinkertn@umich.edu # you want to print out a particular formula, you can simply find out 2801049Sbinkertn@umich.edu # which stats you need by looking in this table. Additionally, when 2811049Sbinkertn@umich.edu # you remove a stat from the stats table and data table, you remove 2821049Sbinkertn@umich.edu # any references to the formula in this table. When a formula is no 2831049Sbinkertn@umich.edu # longer referred to, you remove its entry. 2841049Sbinkertn@umich.edu # 2851049Sbinkertn@umich.edu # COLUMNS: 2861049Sbinkertn@umich.edu # 'stat' is the stat id from the stat table above. 2871049Sbinkertn@umich.edu # 'child' is the stat id of a stat that is used for this formula. 2881049Sbinkertn@umich.edu # There may be many children for any given 'stat' (formula) 2891049Sbinkertn@umich.edu # 2901049Sbinkertn@umich.edu # INDEXES: 2911049Sbinkertn@umich.edu # 'stat' is indexed so you can look up all of the children for a 2921049Sbinkertn@umich.edu # particular stat. 2931049Sbinkertn@umich.edu # 'child' is indexed so that you can remove an entry when a stat is 2941049Sbinkertn@umich.edu # removed. 2951049Sbinkertn@umich.edu # 2961049Sbinkertn@umich.edu self.query(''' 2971049Sbinkertn@umich.edu CREATE TABLE formula_ref( 2981049Sbinkertn@umich.edu fr_stat SMALLINT UNSIGNED NOT NULL, 2991049Sbinkertn@umich.edu fr_run SMALLINT UNSIGNED NOT NULL, 3001049Sbinkertn@umich.edu UNIQUE (fr_stat,fr_run), 3011049Sbinkertn@umich.edu INDEX (fr_stat), 3021049Sbinkertn@umich.edu INDEX (fr_run) 3031049Sbinkertn@umich.edu ) TYPE=InnoDB''') 3041049Sbinkertn@umich.edu 3051049Sbinkertn@umich.edu # COLUMNS: 3061049Sbinkertn@umich.edu # 'event' is the unique event id from the event_desc table 3071049Sbinkertn@umich.edu # 'run' is simulation run id that this event took place in 3081049Sbinkertn@umich.edu # 'tick' is the tick when the event happened 3091049Sbinkertn@umich.edu # 3101049Sbinkertn@umich.edu # INDEXES: 3111049Sbinkertn@umich.edu # 'event' is indexed so you can look up all occurences of a 3121049Sbinkertn@umich.edu # specific event 3131049Sbinkertn@umich.edu # 'run' is indexed so you can find all events in a run 3141049Sbinkertn@umich.edu # 'tick' is indexed because we want the unique thing anyway 3151049Sbinkertn@umich.edu # 'event,run,tick' is unique combination 3161049Sbinkertn@umich.edu self.query(''' 3171049Sbinkertn@umich.edu CREATE TABLE events( 3181049Sbinkertn@umich.edu ev_event SMALLINT UNSIGNED NOT NULL, 3191049Sbinkertn@umich.edu ev_run SMALLINT UNSIGNED NOT NULL, 3201049Sbinkertn@umich.edu ev_tick BIGINT UNSIGNED NOT NULL, 3211049Sbinkertn@umich.edu INDEX(ev_event), 3221049Sbinkertn@umich.edu INDEX(ev_run), 3231049Sbinkertn@umich.edu INDEX(ev_tick), 3241049Sbinkertn@umich.edu UNIQUE(ev_event,ev_run,ev_tick) 3251049Sbinkertn@umich.edu ) TYPE=InnoDB''') 3261049Sbinkertn@umich.edu 3271049Sbinkertn@umich.edu # COLUMNS: 3281049Sbinkertn@umich.edu # 'id' is the unique description id 3291049Sbinkertn@umich.edu # 'name' is the name of the event that occurred 3301049Sbinkertn@umich.edu # 3311049Sbinkertn@umich.edu # INDEXES: 3321049Sbinkertn@umich.edu # 'id' is indexed because it is the primary key and is what you use 3331049Sbinkertn@umich.edu # to look up the descriptions 3341049Sbinkertn@umich.edu # 'name' is indexed so one can find the event based on name 3351049Sbinkertn@umich.edu # 3361049Sbinkertn@umich.edu self.query(''' 3371049Sbinkertn@umich.edu CREATE TABLE event_names( 3381049Sbinkertn@umich.edu en_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, 3391049Sbinkertn@umich.edu en_name VARCHAR(255) NOT NULL, 3401049Sbinkertn@umich.edu PRIMARY KEY (en_id), 3411049Sbinkertn@umich.edu UNIQUE (en_name) 3421049Sbinkertn@umich.edu ) TYPE=InnoDB''') 3431049Sbinkertn@umich.edu 3441049Sbinkertn@umich.edu def clean(self): 3451049Sbinkertn@umich.edu self.query(''' 3461049Sbinkertn@umich.edu DELETE data 3471049Sbinkertn@umich.edu FROM data 3481049Sbinkertn@umich.edu LEFT JOIN runs ON dt_run=rn_id 3491049Sbinkertn@umich.edu WHERE rn_id IS NULL''') 3501049Sbinkertn@umich.edu 3511049Sbinkertn@umich.edu self.query(''' 3521049Sbinkertn@umich.edu DELETE formula_ref 3531049Sbinkertn@umich.edu FROM formula_ref 3541049Sbinkertn@umich.edu LEFT JOIN runs ON fr_run=rn_id 3551049Sbinkertn@umich.edu WHERE rn_id IS NULL''') 3561049Sbinkertn@umich.edu 3571049Sbinkertn@umich.edu self.query(''' 3581049Sbinkertn@umich.edu DELETE formulas 3591049Sbinkertn@umich.edu FROM formulas 3601049Sbinkertn@umich.edu LEFT JOIN formula_ref ON fm_stat=fr_stat 3611049Sbinkertn@umich.edu WHERE fr_stat IS NULL''') 3621049Sbinkertn@umich.edu 3631049Sbinkertn@umich.edu self.query(''' 3641049Sbinkertn@umich.edu DELETE stats 3651049Sbinkertn@umich.edu FROM stats 3661049Sbinkertn@umich.edu LEFT JOIN data ON st_id=dt_stat 3671049Sbinkertn@umich.edu WHERE dt_stat IS NULL''') 3681049Sbinkertn@umich.edu 3691049Sbinkertn@umich.edu self.query(''' 3701049Sbinkertn@umich.edu DELETE subdata 3711049Sbinkertn@umich.edu FROM subdata 3721049Sbinkertn@umich.edu LEFT JOIN data ON sd_stat=dt_stat 3731049Sbinkertn@umich.edu WHERE dt_stat IS NULL''') 3741049Sbinkertn@umich.edu 3751049Sbinkertn@umich.edu self.query(''' 3761049Sbinkertn@umich.edu DELETE events 3771049Sbinkertn@umich.edu FROM events 3781049Sbinkertn@umich.edu LEFT JOIN runs ON ev_run=rn_id 3791049Sbinkertn@umich.edu WHERE rn_id IS NULL''') 3801049Sbinkertn@umich.edu 3811049Sbinkertn@umich.edu self.query(''' 3821049Sbinkertn@umich.edu DELETE event_names 3831049Sbinkertn@umich.edu FROM event_names 3841049Sbinkertn@umich.edu LEFT JOIN events ON en_id=ev_event 3851049Sbinkertn@umich.edu WHERE ev_event IS NULL''') 386