# 5.1 Python Code - Abbildung und Erklärung

    import rhinoscriptsyntax as rs
    import Rhino.Geometry as rg
    import sqlite3 as sq
    import math as ma
    import statistics as st

    #Connect with the Sql database
    con = sq.connect(x)
    cur = con.cursor()

    #read the specific row out of the database for the hight and make a mass addition with the values
    #create parameter for the hight value and a empty list

    DirectionList = ["W" , "S" , "N" , "O", "%%"]

    OList = ["DOORWAY","WINDOW", "%%"]

    Periodlist = ["EARLY EMPIRE","MIDDLE EMPIRE","LATE EMPIRE", "%%"]

    Townlist = ["AECLANUM", "BRESCIA", "HERCULANEUM", "OSTIA", "RIMINI", "ROME", "VERONA", "VICENZA", "%%"]

    Housetypelist = ["DOMUS","HOTEL","MEDIANUM APARTMENT","SHOP APARTMENT","APARTMENT","CENTRAL COURT APARTMENT","%%"]

    Floorlist = ["UG", "G", "1", "2", "%%"]

    Datelist = ["I BC-I AD", "I AD" , "I-II AD" ,"II AD" ,"II-III AD" ,"II-IV AD" ,"III AD" ,"III-IV AD" ,"III-IV AD" ,"IV AD", "%%"]

    PeculiarList = ["NO", "WOLF MOUTH WINDOW","BETWEEN FLATS","%%"]

    bmax = GegBreite + Range
    bmin = GegBreite - Range
    pval = percentvalue/100

    height = []
    hval=0
    for row in cur.execute('SELECT Height, Width FROM Opening JOIN HouseInfo ON Opening.HouseId = HouseInfo.HouseId JOIN Filling ON Opening.OpeningId = Filling.OpeningId Where Opening.Height IS NOT \"\" AND Period LIKE ? AND Opening.Type LIKE ? AND Town LIKE ? AND housetype LIKE ? AND Filling.DirectionOpeningCardinal LIKE ? AND Opening.Floor LIKE ? AND Opening.PeculiarType LIKE ? AND HouseInfo.Date LIKE ? AND Opening.Width BETWEEN ? AND ?',[Periodlist[period],OList[openingtype],Townlist[town],Housetypelist[housetype], DirectionList[direction], Floorlist[Floorlevel],PeculiarList[pl], Datelist[date], bmin,bmax]):
    #use Sql commands to access the specific row and filter it

        #print row

        Propval = row[1]/row[0]
        propheight = GegBreite/Propval
        height.append(propheight)
        #print propheight
    print height
    hpval = int(len(height)*pval)
    sHeight = sorted(i for i in height if minval < i < maxval)
    print sHeight

    hmax = sHeight[-1]
    hmin = sHeight[0]
    hmean = st.mean(sHeight)
    hmed = st.median(sHeight)
    ListenlängeH = len(sHeight)
    UsedData = len(sHeight)

    print "Mean height value :", hmean
    print "Min height value :", hmin
    print "Max height value :", hmax
    print "Median height value :", hmed

    #read the specific row out of the database for the hight and make a mass addition with the values
    #create parameter for the width value and a empty list

    recmean =rg.Rectangle3d.ToNurbsCurve(rg.Rectangle3d(rg.Plane.WorldZX,hmean/100,GegBreite/100))
    recmin =rg.Rectangle3d.ToNurbsCurve(rg.Rectangle3d(rg.Plane.WorldZX,hmin/100,GegBreite/100))
    recmax=rg.Rectangle3d.ToNurbsCurve(rg.Rectangle3d(rg.Plane.WorldZX,hmax/100,GegBreite/100))
    recmed=rg.Rectangle3d.ToNurbsCurve(rg.Rectangle3d(rg.Plane.WorldZX,hmax/100,GegBreite/100))
    reclist= []

    for i in sHeight:
        rl=rg.Rectangle3d.ToNurbsCurve(rg.Rectangle3d(rg.Plane.WorldZX,i/100,GegBreite/100))
        reclist.append(rl)