<commit_before>import os
import httplib
import json
import re

from django.core.management.base import BaseCommand
from django.db.models import Q
from pricing.models import AWS
from pricing.models import GCP

class Command(BaseCommand):

  def add_arguments(self, parser):
    parser.add_argument('command', nargs = 1)


  def handle(self, *args, **options):

    print options['command'][0]

    cmd = options['command'][0]

    if cmd == 'compare':
        # Compare AWS and GCS instances. Try to find matches.

        # apr is AWS queryset
        apr = AWS.objects;
        apr = apr.filter(offer_code = 'AmazonEC2', product_family = 'Compute Instance',
                         term_type = 'OnDemand', tenancy = 'Shared',
                         operating_system = 'Linux')

        gpr = GCP.objects
        gpr = gpr.filter(ptype = 'COMPUTEENGINE', psubtype = 'VMIMAGE', preemptible = False)

        print apr.count(), gpr.count()

        lm = 0.0
        for m in [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0]:
            print "==== memory <", m
            a_1g = apr.filter(memory__lte = m, memory__gt = lm).order_by('instance_type')
            g_1g = gpr.filter(memory__lte = m, memory__gt = lm)
            print a_1g.count(), g_1g.count()

            for a in a_1g:
                print a.instance_type, a.memory, a.vcpu,  a.price_per_unit, a.location

            for g in g_1g:
                print g.pargs, g.memory, g.cores, g.us, g.asia, g.europe

            lm = m

        return

#    # foreach instance_type
#    #   forech location
#    #    get Windows "Bring your own licence<commit_msg>Tweak experimental price comparison.<commit_after>import os
import httplib
import json
import re

from django.core.management.base import BaseCommand
from django.db.models import Min
from django.db.models import Max
from django.db.models import Q
from pricing.models import AWS
from pricing.models import GCP

class Command(BaseCommand):

  def add_arguments(self, parser):
    parser.add_argument('command', nargs = 1)


  def handle(self, *args, **options):

    print options['command'][0]

    cmd = options['command'][0]

    if cmd == 'compare':
        # Compare AWS and GCS instances. Try to find matches.

        # apr is AWS queryset
        apr = AWS.objects;
        apr = apr.filter(offer_code = 'AmazonEC2', product_family = 'Compute Instance',
                         term_type = 'OnDemand', tenancy = 'Shared',
                         operating_system = 'Linux')

        gpr = GCP.objects
        gpr = gpr.filter(ptype = 'COMPUTEENGINE', psubtype = 'VMIMAGE', preemptible = False)

        print apr.count(), gpr.count()

        lm = 0.0
        for m in [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0]:
            print "==== memory < ", m
            a_1g = apr.filter(memory__lte = m, memory__gt = lm).order_by('instance_type')

            for name in a_1g.values('instance_type', 'memory', 'vcpu').distinct():
                x = a_1g.filter(instance_type = name['instance_type'])
                regions = x.values('location', 'price_per_unit').distinct().order_by('location')
                minprice = x.values('price_per_unit').aggregate(Min('price_per_unit'))
                maxprice = x.values('price_per_unit').aggregate(Max('price_per_unit'))
                print name['instance_type'], name['memory'], name['vcpu'], minprice, maxprice
                for r in regions:
                    print '    %s  %f' % (r['location'], r['price_per_unit'])
                

            #a_minprice = a_1g.values('price_per_unit').aggregate(Min('price_per_unit'))
            #a_maxprice = a_1g.values('price_per_unit').aggregate(Max('price_per_unit'))
            #a_instance = a_1g.values('instance_type').distinct()
            #a_vcpu = a_1g.values('vcpu').distinct()
            #a_memory = a_1g.values('memory').distinct()

            #print a_instance, a_memory, a_vcpu, a_minprice, a_maxprice
            #for a in a_1g:
            #    print a.instance_type, a.memory, a.vcpu,  a.price_per_unit, a.location

            g_1g = gpr.filter(memory__lte = m, memory__gt = lm)
            for g in g_1g:
                print g.pargs, g.memory, g.cores, g.us, g.asia, g.europe

            lm = m

        return

#    # foreach instance_type
#    #   forech location
#    #    get Windows "Bring your own licence
{'fraction_non_alphanumeric': 0.12323462414578587, 'fraction_numerical': 0.018906605922551254, 'mean_word_length': 2.274422073079791, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3939617', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1399, 'n_words': 347}