예제 #1
0
def update(request, utility):
  if utility == 'bpa':
    parser = BPAParser(request.GET.get('file', None))
  if utility == 'gb':
    xml_file = request.GET.get('file', '')
    uid = request.GET.get('uid', None)
    if uid is None:
        name = request.GET.get('name', 'New User')
        uid = User.objects.create(name=name).pk

    parser = GreenButtonParser(xml_file, uid)
  return parser.update()
예제 #2
0
def BPA_status(request):
#    return render(request, 'pages/placeholder.html', {'title': 'New England current status'})
    # get current data
    if BPA.objects.count() == 0:
        parser = BPAParser()
        parser.update()
    datum = BPA.latest_point()
    print BPA.latest_point(), BPA.latest_date()
    percent_green = datum.fraction_green() * 100.0
    marginal_fuel = MARGINAL_FUELS[datum.marginal_fuel]

     # compose message
    greenery = str(int(percent_green + 0.5))
    if percent_green < 7:
        message = "Right now in the Pacific Northwest only {p} percent of all electricity is coming from clean wind power. This is below average. It's a really good time to save energy in the Northwest!"
    elif percent_green < 18:
        message = "Right now in the Pacific Northwest {p} percent of all electricity is coming from clean wind power. This is about average for this time of year."
    else:
        message = "Right now in the Pacific Northwest {p} percent of all electricity is coming from clean wind power. This is cleaner than average. Not a bad time to use energy!"
    message = message.format(p = greenery, fuel = marginal_fuel.lower())
    return render(request, 'pages/BPA_status.html', {'marginal_message' : message})
예제 #3
0
파일: views.py 프로젝트: 400yk/watttime
def update(request, utility):
  if utility == 'bpa':
    parser = BPAParser()
  return parser.update()