Skip to content

Commit

Permalink
Generate random value for the risk_score #98
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Nov 8, 2024
1 parent 9882b52 commit 97e1bb9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions component_catalog/migrations/0011_to_delete_temp_fake_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 5.0.9 on 2024-11-08 13:26

from django.db import migrations
from django.db.models import Count


def generate_random_risk_score():
import random
from decimal import Decimal

return Decimal(f"{random.uniform(0, 10):.2f}")


def set_random_risk_score(apps, schema_editor):
Package = apps.get_model("component_catalog", "Package")

qs = Package.objects.annotate(
vulnerability_count=Count("affected_by_vulnerabilities", distinct=True)
).filter(vulnerability_count__gt=0)

for package in qs:
risk_score = generate_random_risk_score()
Package.objects.filter(pk=package.pk).update(risk_score=risk_score)


class Migration(migrations.Migration):

dependencies = [
('component_catalog', '0010_component_risk_score_package_risk_score'),
]

operations = [
migrations.RunPython(set_random_risk_score),
]

0 comments on commit 97e1bb9

Please sign in to comment.