<jupyter_start><jupyter_text>Step5: Post-Processing function step 2<jupyter_code>import os, sys, time, importlib
import osmnx

import geopandas as gpd
import pandas as pd
import networkx as nx
import numpy as np
sys.path.append("../../../GOSTnets")
import GOSTnets as gn

# pip install osmium
# import osmium, logging
# import shapely.wkb as wkblib

from shapely.geometry import LineString, Point
# This is a Jupyter Notebook extension which reloads all of the modules whenever you run the code
# This is optional but good if you are modifying and testing source code
%load_ext autoreload
%autoreload 2
from GOSTnets.load_traffic2 import *
# read graph
G = nx.read_gpickle('./sri_lanka_unclean2_w_time_largest_20200616.pickle')
len(G.edges)
# import shapefile as GPD
study_area = gpd.read_file("./output_edges_shapefiles_merged_20200616/weighted_sec_saved_edges_all_merged2.shp")
study_area
sorted_study_area = study_area.sort_values(by=['weighted_s'], ascending=False)
sorted_study_area
total_cost = 0
total_count = 0
cutoff_row = 0
def sort_weighted_s(index, sec_saved, imp_cost):
    global total_cost
    global total_count
    global cutoff_row
    if total_cost < 20000000 and sec_saved > 0:
        print(f"total_cost before:{total_cost}")
        print(f"imp_cost:{imp_cost}")
        total_cost = total_cost + imp_cost
        total_count += 1
        print(f"sec_saved:{sec_saved}")
        print(f"total_cost:{total_cost}")
        print(f"total_count:{total_count}")
        print(f"cutoff_row:{index}")
        cutoff_row = index
sorted_study_area.apply(lambda x: sort_weighted_s(x.name, x['sec_saved'],x['imp_cost']),axis=1)
total_cost
total_count
cutoff_row<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09106933019976499, 'fraction_numerical': 0.021151586368977675, 'mean_word_length': 5.039007092198582, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '165430', 'license': 'MIT', 'n_tokens_mistral': 633, 'n_tokens_neox': 585, 'n_words': 143, 'path': 'Implementations/FY21/ACC_mapbox_traffic/final_traffic_step5_post_processing_step2.ipynb', 'repo_name': 'worldbank/GOST_PublicGoods', 'size': '1702'}