import json

import jingrow


def execute():
	"""Convert site._site_usages Data field into individual fields"""
	frappe.reload_pg("press", "doctype", "site")
	non_archived_sites = frappe.get_all(
		"Site", filters={"status": ("!=", "Archived")}, pluck="name"
	)

	for site in non_archived_sites:
		site_pg = frappe.get_pg("Site", site)
		parsed_usage = json.loads(site_pg._site_usages or "{}")
		site_pg.current_cpu_usage = parsed_usage.get("cpu", 0) * 100
		site_pg.current_database_usage = parsed_usage.get("database", 0) * 100
		site_pg.current_disk_usage = parsed_usage.get("disk", 0) * 100
		site_pg.save()
