pile_js / Ameobea__robintrack.jsonl
Hamhams's picture
commit files to HF hub
c7f4bd0
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"stocktwits-bot\/src\/stocktwits_api.py","language":"python","identifier":"stocktwits_request","parameters":"(method: str, path: str, *args, headers={}, **kwargs)","argument_list":"","return_statement":"return res.json()","docstring":"Makes a request to the Stocktwits API, passing along the username and password as\n authorization headers.","docstring_summary":"Makes a request to the Stocktwits API, passing along the username and password as\n authorization headers.","docstring_tokens":["Makes","a","request","to","the","Stocktwits","API","passing","along","the","username","and","password","as","authorization","headers","."],"function":"def stocktwits_request(method: str, path: str, *args, headers={}, **kwargs) -> object:\n \"\"\" Makes a request to the Stocktwits API, passing along the username and password as\n authorization headers. \"\"\"\n\n req_function = map_method_name_to_requests_function(method)\n merged_headers = {**headers, \"Authorization\": f\"OAuth {STOCKTWITS_ACCESS_TOKEN}\"}\n url = f\"{STOCKTWITS_BASE_URL}{path}\"\n res = req_function(url, *args, headers=merged_headers, **kwargs)\n return res.json()","function_tokens":["def","stocktwits_request","(","method",":","str",",","path",":","str",",","*","args",",","headers","=","{","}",",","*","*","kwargs",")","->","object",":","req_function","=","map_method_name_to_requests_function","(","method",")","merged_headers","=","{","*","*","headers",",","\"Authorization\"",":","f\"OAuth {STOCKTWITS_ACCESS_TOKEN}\"","}","url","=","f\"{STOCKTWITS_BASE_URL}{path}\"","res","=","req_function","(","url",",","*","args",",","headers","=","merged_headers",",","*","*","kwargs",")","return","res",".","json","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/stocktwits-bot\/src\/stocktwits_api.py#L30-L38"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"set_update_started","parameters":"()","argument_list":"","return_statement":"","docstring":"Marks all data scraping operations as in-progress, invalidates the cache, and marks it as\n invalid until all data scrapes are completed.","docstring_summary":"Marks all data scraping operations as in-progress, invalidates the cache, and marks it as\n invalid until all data scrapes are completed.","docstring_tokens":["Marks","all","data","scraping","operations","as","in","-","progress","invalidates","the","cache","and","marks","it","as","invalid","until","all","data","scrapes","are","completed","."],"function":"def set_update_started():\n \"\"\" Marks all data scraping operations as in-progress, invalidates the cache, and marks it as\n invalid until all data scrapes are completed. \"\"\"\n\n redis_client.delete(\"INSTRUMENTS_FINISHED\")\n redis_client.delete(\"POPULARITIES_FINISHED\")\n redis_client.delete(\"QUOTES_FINISHED\")\n\n lock_cache()","function_tokens":["def","set_update_started","(",")",":","redis_client",".","delete","(","\"INSTRUMENTS_FINISHED\"",")","redis_client",".","delete","(","\"POPULARITIES_FINISHED\"",")","redis_client",".","delete","(","\"QUOTES_FINISHED\"",")","lock_cache","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L9-L17"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"check_if_all_finished","parameters":"()","argument_list":"","return_statement":"","docstring":"Checks if the instrument, popularity, and quote scrapes are all finished. If they are,\n then flush, unlock, and re-enable the cache.","docstring_summary":"Checks if the instrument, popularity, and quote scrapes are all finished. If they are,\n then flush, unlock, and re-enable the cache.","docstring_tokens":["Checks","if","the","instrument","popularity","and","quote","scrapes","are","all","finished",".","If","they","are","then","flush","unlock","and","re","-","enable","the","cache","."],"function":"def check_if_all_finished():\n \"\"\" Checks if the instrument, popularity, and quote scrapes are all finished. If they are,\n then flush, unlock, and re-enable the cache. \"\"\"\n\n all_finished = (\n redis_client.get(\"INSTRUMENTS_FINISHED\")\n and redis_client.get(\"POPULARITIES_FINISHED\")\n and redis_client.get(\"QUOTES_FINISHED\")\n )\n\n if all_finished:\n print(\"All updates finished! Flushing + unlocking cache...\")\n flush_cache()\n populate_popularity_rankings(redis_client, get_db)\n unlock_cache()","function_tokens":["def","check_if_all_finished","(",")",":","all_finished","=","(","redis_client",".","get","(","\"INSTRUMENTS_FINISHED\"",")","and","redis_client",".","get","(","\"POPULARITIES_FINISHED\"",")","and","redis_client",".","get","(","\"QUOTES_FINISHED\"",")",")","if","all_finished",":","print","(","\"All updates finished! Flushing + unlocking cache...\"",")","flush_cache","(",")","populate_popularity_rankings","(","redis_client",",","get_db",")","unlock_cache","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L20-L34"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"set_instruments_finished","parameters":"()","argument_list":"","return_statement":"","docstring":"This is called when the instrument scraper finishes scraping the full list of instruments.\n As soon as popularities and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled.","docstring_summary":"This is called when the instrument scraper finishes scraping the full list of instruments.\n As soon as popularities and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled.","docstring_tokens":["This","is","called","when","the","instrument","scraper","finishes","scraping","the","full","list","of","instruments",".","As","soon","as","popularities","and","quotes","are","finished","as","well","the","data","scrape","is","complete","and","the","cache","can","be","re","-","enabled","."],"function":"def set_instruments_finished():\n \"\"\" This is called when the instrument scraper finishes scraping the full list of instruments.\n As soon as popularities and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled. \"\"\"\n\n redis_client.set(\"INSTRUMENTS_FINISHED\", \"1\")\n check_if_all_finished()","function_tokens":["def","set_instruments_finished","(",")",":","redis_client",".","set","(","\"INSTRUMENTS_FINISHED\"",",","\"1\"",")","check_if_all_finished","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L37-L43"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"set_popularities_finished","parameters":"()","argument_list":"","return_statement":"","docstring":"This is called when the popularity scraper finishes scraping popularities for all symbols.\n As soon as instruments and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled.","docstring_summary":"This is called when the popularity scraper finishes scraping popularities for all symbols.\n As soon as instruments and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled.","docstring_tokens":["This","is","called","when","the","popularity","scraper","finishes","scraping","popularities","for","all","symbols",".","As","soon","as","instruments","and","quotes","are","finished","as","well","the","data","scrape","is","complete","and","the","cache","can","be","re","-","enabled","."],"function":"def set_popularities_finished():\n \"\"\" This is called when the popularity scraper finishes scraping popularities for all symbols.\n As soon as instruments and quotes are finished as well, the data scrape is complete and the\n cache can be re-enabled. \"\"\"\n\n redis_client.set(\"POPULARITIES_FINISHED\", \"1\")\n check_if_all_finished()","function_tokens":["def","set_popularities_finished","(",")",":","redis_client",".","set","(","\"POPULARITIES_FINISHED\"",",","\"1\"",")","check_if_all_finished","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L46-L52"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"set_quotes_finished","parameters":"()","argument_list":"","return_statement":"","docstring":"This is called when the quote scraper finishes scraping quotes for all symbols. As soon as\n instruments and popularities are finished as well, the data scrape is complete and the cache\n can be re-enabled.","docstring_summary":"This is called when the quote scraper finishes scraping quotes for all symbols. As soon as\n instruments and popularities are finished as well, the data scrape is complete and the cache\n can be re-enabled.","docstring_tokens":["This","is","called","when","the","quote","scraper","finishes","scraping","quotes","for","all","symbols",".","As","soon","as","instruments","and","popularities","are","finished","as","well","the","data","scrape","is","complete","and","the","cache","can","be","re","-","enabled","."],"function":"def set_quotes_finished():\n \"\"\" This is called when the quote scraper finishes scraping quotes for all symbols. As soon as\n instruments and popularities are finished as well, the data scrape is complete and the cache\n can be re-enabled. \"\"\"\n\n redis_client.set(\"QUOTES_FINISHED\", \"1\")\n check_if_all_finished()","function_tokens":["def","set_quotes_finished","(",")",":","redis_client",".","set","(","\"QUOTES_FINISHED\"",",","\"1\"",")","check_if_all_finished","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L55-L61"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"flush_cache","parameters":"()","argument_list":"","return_statement":"","docstring":"Removes all cache hashes, removing all existing cache entries.","docstring_summary":"Removes all cache hashes, removing all existing cache entries.","docstring_tokens":["Removes","all","cache","hashes","removing","all","existing","cache","entries","."],"function":"def flush_cache():\n \"\"\" Removes all cache hashes, removing all existing cache entries. \"\"\"\n\n print(\"Flushing cache...\")\n redis_client.flushdb()","function_tokens":["def","flush_cache","(",")",":","print","(","\"Flushing cache...\"",")","redis_client",".","flushdb","(",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L64-L68"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"lock_cache","parameters":"()","argument_list":"","return_statement":"","docstring":"Marks the cache as invalidated and clears all existing cache entries. This causes all\n requests to the backend to be served from MongoDB and prevents new insertions into the\n cache.","docstring_summary":"Marks the cache as invalidated and clears all existing cache entries. This causes all\n requests to the backend to be served from MongoDB and prevents new insertions into the\n cache.","docstring_tokens":["Marks","the","cache","as","invalidated","and","clears","all","existing","cache","entries",".","This","causes","all","requests","to","the","backend","to","be","served","from","MongoDB","and","prevents","new","insertions","into","the","cache","."],"function":"def lock_cache():\n \"\"\" Marks the cache as invalidated and clears all existing cache entries. This causes all\n requests to the backend to be served from MongoDB and prevents new insertions into the\n cache. \"\"\"\n\n redis_client.set(\"CACHE_LOCKED\", \"1\")\n print(\"Cache locked.\")","function_tokens":["def","lock_cache","(",")",":","redis_client",".","set","(","\"CACHE_LOCKED\"",",","\"1\"",")","print","(","\"Cache locked.\"",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L71-L77"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/db.py","language":"python","identifier":"unlock_cache","parameters":"()","argument_list":"","return_statement":"","docstring":"Marks the cache as valid, allowing new entries to be inserted and existing values to be\n used to service requests to the API.","docstring_summary":"Marks the cache as valid, allowing new entries to be inserted and existing values to be\n used to service requests to the API.","docstring_tokens":["Marks","the","cache","as","valid","allowing","new","entries","to","be","inserted","and","existing","values","to","be","used","to","service","requests","to","the","API","."],"function":"def unlock_cache():\n \"\"\" Marks the cache as valid, allowing new entries to be inserted and existing values to be\n used to service requests to the API. \"\"\"\n\n redis_client.delete(\"CACHE_LOCKED\")\n print(\"Cache unlocked.\")","function_tokens":["def","unlock_cache","(",")",":","redis_client",".","delete","(","\"CACHE_LOCKED\"",")","print","(","\"Cache unlocked.\"",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/db.py#L80-L85"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/worker.py","language":"python","identifier":"store_popularities","parameters":"(popularity_map: dict, collection: pymongo.collection.Collection)","argument_list":"","return_statement":"","docstring":"Creates an entry in the database for the popularity.","docstring_summary":"Creates an entry in the database for the popularity.","docstring_tokens":["Creates","an","entry","in","the","database","for","the","popularity","."],"function":"def store_popularities(popularity_map: dict, collection: pymongo.collection.Collection):\n \"\"\" Creates an entry in the database for the popularity. \"\"\"\n\n timestamp = datetime.datetime.utcnow()\n pprint(popularity_map)\n mapped_documents = map(\n lambda key: {\n \"timestamp\": timestamp,\n \"instrument_id\": key,\n \"popularity\": popularity_map[key],\n },\n popularity_map.keys(),\n )\n\n collection.insert_many(mapped_documents)","function_tokens":["def","store_popularities","(","popularity_map",":","dict",",","collection",":","pymongo",".","collection",".","Collection",")",":","timestamp","=","datetime",".","datetime",".","utcnow","(",")","pprint","(","popularity_map",")","mapped_documents","=","map","(","lambda","key",":","{","\"timestamp\"",":","timestamp",",","\"instrument_id\"",":","key",",","\"popularity\"",":","popularity_map","[","key","]",",","}",",","popularity_map",".","keys","(",")",",",")","collection",".","insert_many","(","mapped_documents",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/worker.py#L36-L50"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/worker.py","language":"python","identifier":"store_quotes","parameters":"(quotes: list, collection: pymongo.collection.Collection)","argument_list":"","return_statement":"","docstring":"Creates entries in the database for the provided quotes.","docstring_summary":"Creates entries in the database for the provided quotes.","docstring_tokens":["Creates","entries","in","the","database","for","the","provided","quotes","."],"function":"def store_quotes(quotes: list, collection: pymongo.collection.Collection):\n \"\"\" Creates entries in the database for the provided quotes. \"\"\"\n\n def map_quote(quote: dict) -> dict:\n instrument_id = parse_instrument_url(quote[\"instrument\"])\n\n plucked = {\"instrument_id\": instrument_id, **pluck(DESIRED_QUOTE_KEYS, quote)}\n plucked[\"updated_at\"] = parse_updated_at(plucked[\"updated_at\"])\n return plucked\n\n quotes = list(filter(lambda quote: quote != None, quotes))\n\n def format_quote(quote: dict) -> dict:\n return {\"symbol\": quote[\"symbol\"], \"bid\": quote[\"bid_price\"], \"ask\": quote[\"ask_price\"]}\n\n pprint(list(map(format_quote, quotes)))\n\n # Update the index collection with up-to-date tradability info\n timestamp = datetime.datetime.utcnow()\n\n def update_index_symbol(datum: dict) -> pymongo.operations.UpdateOne:\n data = {\n \"timestamp\": timestamp,\n \"has_traded\": datum.get(\"has_traded\"),\n \"updated_at\": parse_updated_at(datum.get(\"updated_at\")),\n \"trading_halted\": datum.get(\"trading_halted\"),\n }\n instrument_id = parse_instrument_url(datum[\"instrument\"])\n\n return pymongo.operations.UpdateOne({\"instrument_id\": instrument_id}, {\"$set\": data})\n\n ops = list(map(update_index_symbol, quotes))\n INDEX_COL.bulk_write(ops, ordered=False)\n\n quotes = list(map(map_quote, quotes))\n try:\n collection.insert_many(quotes, ordered=False)\n except BulkWriteError as bwe:\n for err in bwe.details[\"writeErrors\"]:\n if \"duplicate key\" not in err[\"errmsg\"]:\n print(\"ERROR: Unhandled exception occured during batch write:\")\n pprint(err)","function_tokens":["def","store_quotes","(","quotes",":","list",",","collection",":","pymongo",".","collection",".","Collection",")",":","def","map_quote","(","quote",":","dict",")","->","dict",":","instrument_id","=","parse_instrument_url","(","quote","[","\"instrument\"","]",")","plucked","=","{","\"instrument_id\"",":","instrument_id",",","*","*","pluck","(","DESIRED_QUOTE_KEYS",",","quote",")","}","plucked","[","\"updated_at\"","]","=","parse_updated_at","(","plucked","[","\"updated_at\"","]",")","return","plucked","quotes","=","list","(","filter","(","lambda","quote",":","quote","!=","None",",","quotes",")",")","def","format_quote","(","quote",":","dict",")","->","dict",":","return","{","\"symbol\"",":","quote","[","\"symbol\"","]",",","\"bid\"",":","quote","[","\"bid_price\"","]",",","\"ask\"",":","quote","[","\"ask_price\"","]","}","pprint","(","list","(","map","(","format_quote",",","quotes",")",")",")","# Update the index collection with up-to-date tradability info","timestamp","=","datetime",".","datetime",".","utcnow","(",")","def","update_index_symbol","(","datum",":","dict",")","->","pymongo",".","operations",".","UpdateOne",":","data","=","{","\"timestamp\"",":","timestamp",",","\"has_traded\"",":","datum",".","get","(","\"has_traded\"",")",",","\"updated_at\"",":","parse_updated_at","(","datum",".","get","(","\"updated_at\"",")",")",",","\"trading_halted\"",":","datum",".","get","(","\"trading_halted\"",")",",","}","instrument_id","=","parse_instrument_url","(","datum","[","\"instrument\"","]",")","return","pymongo",".","operations",".","UpdateOne","(","{","\"instrument_id\"",":","instrument_id","}",",","{","\"$set\"",":","data","}",")","ops","=","list","(","map","(","update_index_symbol",",","quotes",")",")","INDEX_COL",".","bulk_write","(","ops",",","ordered","=","False",")","quotes","=","list","(","map","(","map_quote",",","quotes",")",")","try",":","collection",".","insert_many","(","quotes",",","ordered","=","False",")","except","BulkWriteError","as","bwe",":","for","err","in","bwe",".","details","[","\"writeErrors\"","]",":","if","\"duplicate key\"","not","in","err","[","\"errmsg\"","]",":","print","(","\"ERROR: Unhandled exception occured during batch write:\"",")","pprint","(","err",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/worker.py#L53-L94"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/common.py","language":"python","identifier":"pp_json","parameters":"(x: object)","argument_list":"","return_statement":"","docstring":"Pretty-prints the provided JSON-serializable object.","docstring_summary":"Pretty-prints the provided JSON-serializable object.","docstring_tokens":["Pretty","-","prints","the","provided","JSON","-","serializable","object","."],"function":"def pp_json(x: object) -> None:\n \"\"\" Pretty-prints the provided JSON-serializable object. \"\"\"\n print(json.dumps(x, indent=2, sort_keys=True))","function_tokens":["def","pp_json","(","x",":","object",")","->","None",":","print","(","json",".","dumps","(","x",",","indent","=","2",",","sort_keys","=","True",")",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/common.py#L7-L9"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/common.py","language":"python","identifier":"parse_throttle_res","parameters":"(msg: str)","argument_list":"","return_statement":"return int(float(match[1]) + 2.0)","docstring":"Given the response of a throttle message, returns the cooldown.","docstring_summary":"Given the response of a throttle message, returns the cooldown.","docstring_tokens":["Given","the","response","of","a","throttle","message","returns","the","cooldown","."],"function":"def parse_throttle_res(msg: str) -> int:\n \"\"\" Given the response of a throttle message, returns the cooldown. \"\"\"\n match = re.match(THROTTLE_RGX, msg)\n if not match:\n print(\n \"ERROR: Unable to parse throttle message. {}{}\".format(msg, \"Assuming 1.5 minutes...\")\n )\n return 120\n\n return int(float(match[1]) + 2.0)","function_tokens":["def","parse_throttle_res","(","msg",":","str",")","->","int",":","match","=","re",".","match","(","THROTTLE_RGX",",","msg",")","if","not","match",":","print","(","\"ERROR: Unable to parse throttle message. {}{}\"",".","format","(","msg",",","\"Assuming 1.5 minutes...\"",")",")","return","120","return","int","(","float","(","match","[","1","]",")","+","2.0",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/common.py#L15-L24"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/popularity_ranking.py","language":"python","identifier":"compute_popularity_rankings","parameters":"(get_db)","argument_list":"","return_statement":"return ret","docstring":"Returns a list of all symbols ordered by current popularity, ordered most to least\n popular.","docstring_summary":"Returns a list of all symbols ordered by current popularity, ordered most to least\n popular.","docstring_tokens":["Returns","a","list","of","all","symbols","ordered","by","current","popularity","ordered","most","to","least","popular","."],"function":"def compute_popularity_rankings(get_db) -> list:\n \"\"\" Returns a list of all symbols ordered by current popularity, ordered most to least\n popular. \"\"\"\n\n db = get_db()\n\n print(\"Performing popularity aggregation query\")\n res = list(db[\"popularity\"].aggregate(get_popularity_ranking_query()))\n\n unique_instrument_ids = [datum[\"_id\"] for datum in res]\n index_res = db[\"index\"].find({ \"instrument_id\": { \"$in\": unique_instrument_ids } })\n instrument_data = {}\n for item in index_res:\n instrument_data[item[\"instrument_id\"]] = item\n\n ret = []\n for datum in res:\n instrument_datum = instrument_data.get(datum[\"_id\"])\n if instrument_datum is None:\n continue\n\n ret.append({ \"latest_popularity\": datum[\"latest_popularity\"], \"name\": instrument_datum[\"simple_name\"], \"symbol\": instrument_datum[\"symbol\"] })\n\n return ret","function_tokens":["def","compute_popularity_rankings","(","get_db",")","->","list",":","db","=","get_db","(",")","print","(","\"Performing popularity aggregation query\"",")","res","=","list","(","db","[","\"popularity\"","]",".","aggregate","(","get_popularity_ranking_query","(",")",")",")","unique_instrument_ids","=","[","datum","[","\"_id\"","]","for","datum","in","res","]","index_res","=","db","[","\"index\"","]",".","find","(","{","\"instrument_id\"",":","{","\"$in\"",":","unique_instrument_ids","}","}",")","instrument_data","=","{","}","for","item","in","index_res",":","instrument_data","[","item","[","\"instrument_id\"","]","]","=","item","ret","=","[","]","for","datum","in","res",":","instrument_datum","=","instrument_data",".","get","(","datum","[","\"_id\"","]",")","if","instrument_datum","is","None",":","continue","ret",".","append","(","{","\"latest_popularity\"",":","datum","[","\"latest_popularity\"","]",",","\"name\"",":","instrument_datum","[","\"simple_name\"","]",",","\"symbol\"",":","instrument_datum","[","\"symbol\"","]","}",")","return","ret"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/popularity_ranking.py#L19-L42"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/popularity_ranking.py","language":"python","identifier":"set_popularity_rankings","parameters":"(redis_client, rankings: Cursor)","argument_list":"","return_statement":"","docstring":"Sets the popularity rankings for each symbol into Redis.","docstring_summary":"Sets the popularity rankings for each symbol into Redis.","docstring_tokens":["Sets","the","popularity","rankings","for","each","symbol","into","Redis","."],"function":"def set_popularity_rankings(redis_client, rankings: Cursor):\n \"\"\" Sets the popularity rankings for each symbol into Redis. \"\"\"\n\n rankings_map = {}\n rankings_list = []\n ranking = 0\n print(\"Finished fetching population data.\")\n for entry in rankings:\n symbol = entry.get(\"symbol\")\n name = entry.get(\"name\")\n if symbol is None:\n continue\n popularity = entry.get(\"latest_popularity\", 0)\n\n ranking += 1\n rankings_map[symbol] = ranking\n rankings_list.append(json.dumps({\"symbol\": symbol, \"popularity\": popularity, \"name\": name}))\n\n print(\"Setting popularity rankings hash...\")\n # Populate the popularity mapping hash used to map symbol to ranking\n redis_client.delete(\"popularity_rankings\")\n redis_client.hmset(\"popularity_rankings\", rankings_map)\n print(\"Setting popularity list...\")\n # Populate the list rankings all symbols from most to least popular in order\n redis_client.delete(\"popularity_list\")\n redis_client.rpush(\"popularity_list\", *rankings_list)\n print(\"Finished computing popularity caches\")","function_tokens":["def","set_popularity_rankings","(","redis_client",",","rankings",":","Cursor",")",":","rankings_map","=","{","}","rankings_list","=","[","]","ranking","=","0","print","(","\"Finished fetching population data.\"",")","for","entry","in","rankings",":","symbol","=","entry",".","get","(","\"symbol\"",")","name","=","entry",".","get","(","\"name\"",")","if","symbol","is","None",":","continue","popularity","=","entry",".","get","(","\"latest_popularity\"",",","0",")","ranking","+=","1","rankings_map","[","symbol","]","=","ranking","rankings_list",".","append","(","json",".","dumps","(","{","\"symbol\"",":","symbol",",","\"popularity\"",":","popularity",",","\"name\"",":","name","}",")",")","print","(","\"Setting popularity rankings hash...\"",")","# Populate the popularity mapping hash used to map symbol to ranking","redis_client",".","delete","(","\"popularity_rankings\"",")","redis_client",".","hmset","(","\"popularity_rankings\"",",","rankings_map",")","print","(","\"Setting popularity list...\"",")","# Populate the list rankings all symbols from most to least popular in order","redis_client",".","delete","(","\"popularity_list\"",")","redis_client",".","rpush","(","\"popularity_list\"",",","*","rankings_list",")","print","(","\"Finished computing popularity caches\"",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/popularity_ranking.py#L45-L71"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/popularity_ranking.py","language":"python","identifier":"populate_popularity_rankings","parameters":"(redis_client, get_db)","argument_list":"","return_statement":"","docstring":"Compute the popularity rankings cache and set it into Redis.","docstring_summary":"Compute the popularity rankings cache and set it into Redis.","docstring_tokens":["Compute","the","popularity","rankings","cache","and","set","it","into","Redis","."],"function":"def populate_popularity_rankings(redis_client, get_db):\n \"\"\" Compute the popularity rankings cache and set it into Redis. \"\"\"\n\n rankings = compute_popularity_rankings(get_db)\n set_popularity_rankings(redis_client, rankings)","function_tokens":["def","populate_popularity_rankings","(","redis_client",",","get_db",")",":","rankings","=","compute_popularity_rankings","(","get_db",")","set_popularity_rankings","(","redis_client",",","rankings",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/popularity_ranking.py#L74-L78"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scraper\/src\/scrape_instruments.py","language":"python","identifier":"get_tradable_instruments","parameters":"(instruments: List[Dict[str, object]])","argument_list":"","return_statement":"return filter(lambda instrument: instrument.get(\"tradability\") == \"tradable\", instruments)","docstring":"Filters the provided list of instruments to only include those that are tradeable","docstring_summary":"Filters the provided list of instruments to only include those that are tradeable","docstring_tokens":["Filters","the","provided","list","of","instruments","to","only","include","those","that","are","tradeable"],"function":"def get_tradable_instruments(instruments: List[Dict[str, object]]) -> Iterable[Dict[str, object]]:\n \"\"\" Filters the provided list of instruments to only include those that are tradeable \"\"\"\n\n return filter(lambda instrument: instrument.get(\"tradability\") == \"tradable\", instruments)","function_tokens":["def","get_tradable_instruments","(","instruments",":","List","[","Dict","[","str",",","object","]","]",")","->","Iterable","[","Dict","[","str",",","object","]","]",":","return","filter","(","lambda","instrument",":","instrument",".","get","(","\"tradability\"",")","==","\"tradable\"",",","instruments",")"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scraper\/src\/scrape_instruments.py#L17-L20"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"scripts\/aggregate_by_category.py","language":"python","identifier":"get_all_stock_fundamentals","parameters":"()","argument_list":"","return_statement":"return fundamentals_by_instrument_id","docstring":"Returns a dict mapping instrument id to stock fundamentals","docstring_summary":"Returns a dict mapping instrument id to stock fundamentals","docstring_tokens":["Returns","a","dict","mapping","instrument","id","to","stock","fundamentals"],"function":"def get_all_stock_fundamentals():\n \"\"\"\n Returns a dict mapping instrument id to stock fundamentals\n \"\"\"\n\n db = get_db()\n\n fundamentals_by_instrument_id = dict()\n all_fundamentals = list(db[\"fundamentals\"].find())\n for f in all_fundamentals:\n fundamentals_by_instrument_id[f[\"instrument_id\"]] = f\n\n return fundamentals_by_instrument_id","function_tokens":["def","get_all_stock_fundamentals","(",")",":","db","=","get_db","(",")","fundamentals_by_instrument_id","=","dict","(",")","all_fundamentals","=","list","(","db","[","\"fundamentals\"","]",".","find","(",")",")","for","f","in","all_fundamentals",":","fundamentals_by_instrument_id","[","f","[","\"instrument_id\"","]","]","=","f","return","fundamentals_by_instrument_id"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/scripts\/aggregate_by_category.py#L14-L26"}
{"nwo":"Ameobea\/robintrack","sha":"d74acc0b8e9f360864d1606134123a9430f8c223","path":"python_common\/db.py","language":"python","identifier":"get_db","parameters":"()","argument_list":"","return_statement":"return mongo_client[\"robinhood\"]","docstring":"Returns an instance of the MongoDB database for this project.","docstring_summary":"Returns an instance of the MongoDB database for this project.","docstring_tokens":["Returns","an","instance","of","the","MongoDB","database","for","this","project","."],"function":"def get_db():\n \"\"\" Returns an instance of the MongoDB database for this project. \"\"\"\n\n return mongo_client[\"robinhood\"]","function_tokens":["def","get_db","(",")",":","return","mongo_client","[","\"robinhood\"","]"],"url":"https:\/\/github.com\/Ameobea\/robintrack\/blob\/d74acc0b8e9f360864d1606134123a9430f8c223\/python_common\/db.py#L26-L29"}