Skip to content

Instantly share code, notes, and snippets.

@adammcmaster
Created June 11, 2020 12:11
Show Gist options
  • Save adammcmaster/a923c75e149e8fc92c7b2cf97cf183df to your computer and use it in GitHub Desktop.
Save adammcmaster/a923c75e149e8fc92c7b2cf97cf183df to your computer and use it in GitHub Desktop.
Estimating the cost of a list of projects
import datetime
import dateutil.parser
from panoptes_client import Panoptes, Project
PROJECT_IDS = (
10371,
10524,
11414,
12259,
10820,
9368,
9459,
)
COSTS = {
'rds_per_gb_month': 0.115,
'network_per_gb': 0.085,
's3_per_gb_month': 0.023,
'classification_gb': 2 / 1024**2, # 2 KB
'subject_db_gb': 2 / 1024**2, # 2 KB
'subject_s3_gb': 5 / 1024, # 5 MB
}
Panoptes.connect(
username='',
password='',
admin=True,
)
COSTS['per_classification'] = (
COSTS['network_per_gb'] * COSTS['classification_gb']
+ COSTS['network_per_gb'] * COSTS['subject_s3_gb']
)
COSTS['per_classification_month'] = (
COSTS['rds_per_gb_month'] * COSTS['classification_gb']
)
COSTS['per_subject'] = (
COSTS['network_per_gb'] * COSTS['subject_db_gb']
+ COSTS['network_per_gb'] * COSTS['subject_s3_gb']
)
COSTS['per_subject_month'] = (
COSTS['rds_per_gb_month'] * COSTS['subject_db_gb']
+ COSTS['s3_per_gb_month'] * COSTS['subject_s3_gb']
)
classification_count = 0
subject_count = 0
total_cost = 0.0
print("Cost Duration Project name")
for project in map(Project.find, PROJECT_IDS):
project_age = dateutil.relativedelta.relativedelta(
datetime.datetime.now(datetime.timezone.utc),
dateutil.parser.parse(project.created_at)
)
project_age = project_age.years * 12 + project_age.months
project_cost = (
project.classifications_count * COSTS['per_classification']
+ project.classifications_count * project_age * COSTS['per_classification_month']
+ project.subjects_count * COSTS['per_subject']
+ project.subjects_count * COSTS['per_subject_month']
)
print("{:7.2f} {:3d} months {}".format(project_cost, project_age, project.display_name))
total_cost += project_cost
print("\nTotal cost: ${:2.2f}".format(total_cost))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment