Skip to content

Instantly share code, notes, and snippets.

@tashrifbillah
Last active June 26, 2024 21:00
Show Gist options
  • Save tashrifbillah/f8451473a78b639e828c42fe419d029c to your computer and use it in GitHub Desktop.
Save tashrifbillah/f8451473a78b639e828c42fe419d029c to your computer and use it in GitHub Desktop.
Reorder charts on DPdash
#!/usr/bin/env python
import json
reordered='/data/predict1/charts1.json'
raw='/data/predict1/predict-mongodb-backup/charts_20240612.json'
# find out the private charts in raw
# print 0-indexed indices of private charts from raw file
with open(reordered) as f:
charts=f.read().strip().split('\n')
reordered=[]
for c in charts
reordered.append(json.loads(c))
with open(raw) as f:
charts=f.read().strip().split('\n')
raw=[]
for c in charts
raw.append(json.loads(c))
# iterate through reordered
# look for (title,owner) pair in raw
# if it does not exist, print index
# Dheshan will complete this code
@tashrifbillah
Copy link
Author

cc @sbouix

@tashrifbillah
Copy link
Author

@dheshanm
Copy link

dheshanm commented Jun 26, 2024

I have the completed code here:

import json

reordered_path = "/data/predict1/charts1.json"
raw_path = "/data/predict1/predict-mongodb-backup/charts_20240612.json"

from typing import List, Tuple

reordered = []
reordered_tuples: List[Tuple[str, str]] = []

with open(reordered_path) as f:
    charts = f.read().strip().split("\n")

    for c in charts:
        chart = json.loads(c)

        chart_title = chart["title"]
        chart_owner = chart["owner"]
        reordered_tuples.append((chart_title, chart_owner))

        reordered.append(chart)
        
# look for (title,owner) pair in raw
# if it does not exist, print index
with open(raw_path) as f:
    charts = f.read().strip().split("\n")

    for idx, c in enumerate(charts):
        chart = json.loads(c)

        chart_title = chart["title"]
        chart_owner = chart["owner"]

        if (chart_title, chart_owner) not in reordered_tuples:
            print(idx)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment