Exemplo n.º 1
0
    def sim(self):

        scenario = []
        commodity = Commodity.all().filter("name =", 'Electricity').get()
        delivery_point_query = DeliveryPoint.all().filter(
            "commodity =", commodity)

        #market_query = Market.all().filter("delivery_point IN",[dp for dp in delivery_point_query])

        period_query = Period.all().filter("type =", 'Hour')
        profile = Profile.all().filter("granularity =", 'hourly').get()
        calendar = Calendar.all().filter("name =", 'Base').get()

        delivery_query = Delivery.all().filter("profile =", profile).filter(
            "calendar =", calendar)
        counter = 0
        for period in period_query:

            delivery = db.GqlQuery(
                "SELECT * FROM Delivery " +
                "WHERE profile = :1 AND calendar = :2 " + "AND period = :3",
                profile, calendar, period).get()

            market = db.GqlQuery(
                "SELECT * FROM Market " + "WHERE delivery_point = :1 " +
                "AND delivery = :3", [dp for dp in delivery_point_query],
                delivery)
            scenario.append(market)
            counter = counter + 1

        self.scenario = scenario
Exemplo n.º 2
0
    def sim(self):
        
        scenario = []
        commodity = Commodity.all().filter("name =",'Electricity').get()
        delivery_point_query = DeliveryPoint.all().filter("commodity =",commodity)
        
        #market_query = Market.all().filter("delivery_point IN",[dp for dp in delivery_point_query])
        
        period_query = Period.all().filter("type =",'Hour')
        profile = Profile.all().filter("granularity =",'hourly').get()
        calendar = Calendar.all().filter("name =",'Base').get()
        
        delivery_query = Delivery.all().filter("profile =",profile).filter("calendar =",calendar)
        counter = 0
        for period in period_query:

            delivery = db.GqlQuery("SELECT * FROM Delivery " +
                                   "WHERE profile = :1 AND calendar = :2 " +
                                   "AND period = :3",
                                   profile,calendar,period).get()

            market = db.GqlQuery("SELECT * FROM Market " +
                                 "WHERE delivery_point = :1 " +
                                 "AND delivery = :3",
                                 [dp for dp in delivery_point_query], delivery)
            scenario.append(market)
            counter = counter + 1

        self.scenario = scenario
Exemplo n.º 3
0
def price(file):
    
    price_reader = csv.reader(file, delimiter=',', quotechar="'")
    #price_reader = csv.reader(open(file, 'rb'), delimiter=',', quotechar="'")
    #price_reader = file
   
    for row in price_reader:
        
        eod = time.strptime(row[0],"%m/%d/%Y")
        eod = datetime.date(eod[0],eod[1],eod[2])
        
        eod_query = EndOfDay.all()
        eod_instance = eod_query.filter("date =",eod).get()
        if not(eod_instance):
            eod_instance = EndOfDay(date=eod)
        
        delivery_point_query = DeliveryPoint.all()
        delivery_point_nickname = row[1]
        delivery_point_instance = delivery_point_query.filter("nickname =", delivery_point_nickname).get()
        
        period_start = time.strptime(row[2],"%m/%d/%Y")
        period_start = datetime.date(period_start[0],period_start[1],period_start[2])
        period_query = Period.all()
        period_instance = period_query.filter("first_date =",period_start).get()
        
        if period_instance:
                
            profile_query = Profile.all()
            profile_instance = profile_query.filter("name =",'Flat').get()
            
            calendar_query = Calendar.all()
            calendar_instance = calendar_query.filter("name =",'Base').get()
            
            delivery_query = Delivery.all()
            delivery_instance = delivery_query.filter("period =",period_instance).filter("calendar =",calendar_instance).filter("profile =",profile_instance).get()
            if not(delivery_instance):
                delivery_instance = Delivery(period=period_instance,calendar=calendar_instance,profile=profile_instance)
                delivery_instance.put()
            
            price_instance = Price(mid=float(row[3]),
                            bid=float(row[4]),
                            offer=float(row[5]))
            price_instance.put()
            
            eod_instance.put()
            market_instance = Market(eod=eod_instance,
                                     delivery_point = delivery_point_instance,
                                     price = price_instance,
                                     delivery = delivery_instance)
            market_instance.put()
    
    return True
Exemplo n.º 4
0
def pjm_da_price(file):
    
    result = urllib2.urlopen(file)
    read = False
    counter = 0
    file = result.readlines()
    for row in file:

        row = row.split(',')

        if row[0]=='End of Day Ahead LMP Data':
            break
        
        if read:
        
            if not(counter):
                eod = time.strptime(row[0],"%Y%m%d")
                eod = datetime.datetime(eod[0],eod[1],eod[2])
                
                eod_query = EndOfDay.all()
                eod_instance = eod_query.filter("date =",eod.date()).get()
                if not(eod_instance):
                    eod_instance = EndOfDay(date=eod.date())
            
            delivery_point_query = DeliveryPoint.all()
            delivery_point_node_id = int(row[1])
            delivery_point_instance = delivery_point_query.filter("node_id =", delivery_point_node_id).get()
            
            if delivery_point_instance:
                
                for iHour in range(24):
                    
                    if not(counter):
                        period_start = eod + datetime.timedelta(hours=iHour)
                        period_end = period_start + datetime.timedelta(hours=1)
                        period_query = Period.all()
                        period_instance = period_query.filter("first_date =",period_start).filter("last_date =",period_end).get()
                        
                    if not(period_instance):
                        period_instance = Period(name=period_start.strftime('%b %d %Y') + ' HE' + str(iHour + 1),
                                           first_date=period_start,
                                           last_date=period_end,
                                           type='Hour')
                        period_instance.put()
                        
                            
                    profile_query = Profile.all()
                    profile_instance = profile_query.filter("name =",'Flat').get()
                    
                    calendar_query = Calendar.all()
                    calendar_instance = calendar_query.filter("name =",'Base').get()
                    
                    delivery_query = Delivery.all()
                    delivery_instance = delivery_query.filter("period =",period_instance).filter("calendar =",calendar_instance).filter("profile =",profile_instance).get()
                    
                    if not(delivery_instance):
                        delivery_instance = Delivery(period=period_instance,calendar=calendar_instance,profile=profile_instance)
                        delivery_instance.put()
                    
                    price_instance = Price(day_ahead=float(row[7+iHour*3]),
                                    congestion=float(row[8+iHour*3]),
                                    loss=float(row[9+iHour*3]))
                    price_instance.put()
                    
                    eod_instance.put()
                    market_instance = Market(eod=eod_instance,
                                             delivery_point = delivery_point_instance,
                                             price = price_instance,
                                             delivery = delivery_instance)
                    market_instance.put()
                        
                counter = counter + 1
    
        if row[0]=='Date':
            read=True
                
    return True
Exemplo n.º 5
0
def pjm_da_price(file):

    result = urllib2.urlopen(file)
    read = False
    counter = 0
    file = result.readlines()
    for row in file:

        row = row.split(',')

        if row[0] == 'End of Day Ahead LMP Data':
            break

        if read:

            if not (counter):
                eod = time.strptime(row[0], "%Y%m%d")
                eod = datetime.datetime(eod[0], eod[1], eod[2])

                eod_query = EndOfDay.all()
                eod_instance = eod_query.filter("date =", eod.date()).get()
                if not (eod_instance):
                    eod_instance = EndOfDay(date=eod.date())

            delivery_point_query = DeliveryPoint.all()
            delivery_point_node_id = int(row[1])
            delivery_point_instance = delivery_point_query.filter(
                "node_id =", delivery_point_node_id).get()

            if delivery_point_instance:

                for iHour in range(24):

                    if not (counter):
                        period_start = eod + datetime.timedelta(hours=iHour)
                        period_end = period_start + datetime.timedelta(hours=1)
                        period_query = Period.all()
                        period_instance = period_query.filter(
                            "first_date =",
                            period_start).filter("last_date =",
                                                 period_end).get()

                    if not (period_instance):
                        period_instance = Period(
                            name=period_start.strftime('%b %d %Y') + ' HE' +
                            str(iHour + 1),
                            first_date=period_start,
                            last_date=period_end,
                            type='Hour')
                        period_instance.put()

                    profile_query = Profile.all()
                    profile_instance = profile_query.filter("name =",
                                                            'Flat').get()

                    calendar_query = Calendar.all()
                    calendar_instance = calendar_query.filter(
                        "name =", 'Base').get()

                    delivery_query = Delivery.all()
                    delivery_instance = delivery_query.filter(
                        "period =", period_instance).filter(
                            "calendar =",
                            calendar_instance).filter("profile =",
                                                      profile_instance).get()

                    if not (delivery_instance):
                        delivery_instance = Delivery(
                            period=period_instance,
                            calendar=calendar_instance,
                            profile=profile_instance)
                        delivery_instance.put()

                    price_instance = Price(day_ahead=float(row[7 + iHour * 3]),
                                           congestion=float(row[8 +
                                                                iHour * 3]),
                                           loss=float(row[9 + iHour * 3]))
                    price_instance.put()

                    eod_instance.put()
                    market_instance = Market(
                        eod=eod_instance,
                        delivery_point=delivery_point_instance,
                        price=price_instance,
                        delivery=delivery_instance)
                    market_instance.put()

                counter = counter + 1

        if row[0] == 'Date':
            read = True

    return True
Exemplo n.º 6
0
def price(file):

    price_reader = csv.reader(file, delimiter=',', quotechar="'")
    #price_reader = csv.reader(open(file, 'rb'), delimiter=',', quotechar="'")
    #price_reader = file

    for row in price_reader:

        eod = time.strptime(row[0], "%m/%d/%Y")
        eod = datetime.date(eod[0], eod[1], eod[2])

        eod_query = EndOfDay.all()
        eod_instance = eod_query.filter("date =", eod).get()
        if not (eod_instance):
            eod_instance = EndOfDay(date=eod)

        delivery_point_query = DeliveryPoint.all()
        delivery_point_nickname = row[1]
        delivery_point_instance = delivery_point_query.filter(
            "nickname =", delivery_point_nickname).get()

        period_start = time.strptime(row[2], "%m/%d/%Y")
        period_start = datetime.date(period_start[0], period_start[1],
                                     period_start[2])
        period_query = Period.all()
        period_instance = period_query.filter("first_date =",
                                              period_start).get()

        if period_instance:

            profile_query = Profile.all()
            profile_instance = profile_query.filter("name =", 'Flat').get()

            calendar_query = Calendar.all()
            calendar_instance = calendar_query.filter("name =", 'Base').get()

            delivery_query = Delivery.all()
            delivery_instance = delivery_query.filter(
                "period =",
                period_instance).filter("calendar =",
                                        calendar_instance).filter(
                                            "profile =",
                                            profile_instance).get()
            if not (delivery_instance):
                delivery_instance = Delivery(period=period_instance,
                                             calendar=calendar_instance,
                                             profile=profile_instance)
                delivery_instance.put()

            price_instance = Price(mid=float(row[3]),
                                   bid=float(row[4]),
                                   offer=float(row[5]))
            price_instance.put()

            eod_instance.put()
            market_instance = Market(eod=eod_instance,
                                     delivery_point=delivery_point_instance,
                                     price=price_instance,
                                     delivery=delivery_instance)
            market_instance.put()

    return True