Skip to content

Commit

Permalink
Add overprice scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Jan 16, 2024
1 parent 38f88c3 commit 55341f2
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 18 deletions.
3 changes: 2 additions & 1 deletion requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ web3
eth-account
eth-tester
PyJWT
djangorestframework-simplejwt
djangorestframework-simplejwt
hcloud
20 changes: 20 additions & 0 deletions stats-backend/api2/migrations/0006_glm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.7 on 2024-01-16 19:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api2', '0005_healtchecktask'),
]

operations = [
migrations.CreateModel(
name='GLM',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('current_price', models.FloatField(null=True)),
],
),
]
18 changes: 18 additions & 0 deletions stats-backend/api2/migrations/0007_offer_monthly_price_usd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2024-01-16 19:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api2', '0006_glm'),
]

operations = [
migrations.AddField(
model_name='offer',
name='monthly_price_usd',
field=models.FloatField(blank=True, null=True),
),
]
23 changes: 23 additions & 0 deletions stats-backend/api2/migrations/0008_ec2instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.7 on 2024-01-16 21:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api2', '0007_offer_monthly_price_usd'),
]

operations = [
migrations.CreateModel(
name='EC2Instance',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('vcpu', models.IntegerField(null=True)),
('memory', models.FloatField(null=True)),
('price_usd', models.DecimalField(decimal_places=2, max_digits=10, null=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.1.7 on 2024-01-16 21:23

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api2', '0008_ec2instance'),
]

operations = [
migrations.AddField(
model_name='offer',
name='is_overpriced',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='offer',
name='overpriced_compared_to',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api2.ec2instance'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2024-01-16 21:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api2', '0009_offer_is_overpriced_offer_overpriced_compared_to'),
]

operations = [
migrations.AddField(
model_name='offer',
name='suggest_env_per_hour_price',
field=models.FloatField(null=True),
),
]
18 changes: 18 additions & 0 deletions stats-backend/api2/migrations/0011_offer_times_more_expensive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.7 on 2024-01-16 22:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api2', '0010_offer_suggest_env_per_hour_price'),
]

operations = [
migrations.AddField(
model_name='offer',
name='times_more_expensive',
field=models.FloatField(null=True),
),
]
21 changes: 21 additions & 0 deletions stats-backend/api2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ class Node(models.Model):
created_at = models.DateTimeField(auto_now_add=True)


class EC2Instance(models.Model):
name = models.CharField(max_length=100, unique=True)
vcpu = models.IntegerField(null=True)
memory = models.FloatField(null=True) # Assuming memory is in GB
price_usd = models.DecimalField(max_digits=10, decimal_places=2, null=True)

def __str__(self):
return self.name

class Offer(models.Model):
properties = models.JSONField(null=True)
runtime = models.CharField(max_length=42)
provider = models.ForeignKey(Node, on_delete=models.CASCADE)
updated_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True)
monthly_price_glm = models.FloatField(null=True, blank=True)
monthly_price_usd = models.FloatField(null=True, blank=True)
is_overpriced = models.BooleanField(default=False)
overpriced_compared_to = models.ForeignKey(EC2Instance, on_delete=models.CASCADE, null=True)
suggest_env_per_hour_price = models.FloatField(null=True)
times_more_expensive = models.FloatField(null=True)

class Meta:
unique_together = (
Expand All @@ -38,3 +52,10 @@ class HealtcheckTask(models.Model):
status = models.TextField()
updated_at = models.DateTimeField(auto_now=True)
created_at = models.DateTimeField(auto_now_add=True)


class GLM(models.Model):
current_price = models.FloatField(null=True)



25 changes: 14 additions & 11 deletions stats-backend/api2/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from rest_framework import serializers
from .models import Node, Offer
from .models import Node, Offer, EC2Instance

class EC2InstanceSerializer(serializers.ModelSerializer):
class Meta:
model = EC2Instance
fields = '__all__'

class OfferSerializer(serializers.ModelSerializer):
overpriced_compared_to = EC2InstanceSerializer(read_only=True)


class Meta:
model = Offer
fields = ["runtime", "monthly_price_glm", "properties", "updated_at"]

fields = [
"runtime", "monthly_price_glm", "properties",
"updated_at", "monthly_price_usd", "is_overpriced",
"overpriced_compared_to", "suggest_env_per_hour_price"
]

class NodeSerializer(serializers.ModelSerializer):
runtimes = serializers.SerializerMethodField("get_offers")
Expand All @@ -27,11 +37,4 @@ class Meta:

def get_offers(self, node):
offers = Offer.objects.filter(provider=node)
data = {}
for obj in offers:
data[obj.runtime] = {
"monthly_price_glm": obj.monthly_price_glm,
"updated_at": obj.updated_at,
"properties": obj.properties,
}
return data
return {offer.runtime: OfferSerializer(offer).data for offer in offers}
Loading

0 comments on commit 55341f2

Please sign in to comment.