crcdng commited on
Commit
f0fd2aa
·
1 Parent(s): f6f9a04

hazard factor

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +15 -5
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -5,12 +5,21 @@ import requests
5
 
6
  NASA_API_KEY = os.getenv("NASA_API_KEY")
7
 
8
- def private_fn():
9
  """
10
- This function is private and not intended for public use.
11
- It is used to demonstrate the use of a private function in the code.
 
 
 
 
 
 
12
  """
13
- return "This is a private function."
 
 
 
14
 
15
 
16
  def fetch_nasa():
@@ -20,6 +29,7 @@ def fetch_nasa():
20
  Returns:
21
  Near Earth Objects for the next seven days.
22
  """
 
23
  url = "https://api.nasa.gov/neo/rest/v1/feed"
24
 
25
  rawdata = requests.get(
@@ -34,5 +44,5 @@ def fetch_nasa():
34
 
35
  return json.get("near_earth_objects", {}).get("2025-06-11", [])
36
 
37
- demo = gr.Interface(fn=fetch_nasa, inputs=None, outputs="text")
38
  demo.launch(mcp_server=True)
 
5
 
6
  NASA_API_KEY = os.getenv("NASA_API_KEY")
7
 
8
+ def calc_asteroid_factor(json, weight=1.0):
9
  """
10
+ Calculates the astoriod doom probability.
11
+
12
+ Args:
13
+ json (object): The data structure returned frm NASA
14
+ weight (float): The weight to apply to the hazard factor.
15
+
16
+ Returns:
17
+ Weighted factor for Near Earth Object impact for the next seven days.
18
  """
19
+ # vibe coded, replace with real code later
20
+ matches = re.findall(r'"is_potentially_hazardous_asteroid"\s*:\s*(true|false)', json)
21
+ hazard_list = list(filter(lambda x: x == "true", matches))
22
+ return (len(hazard_list)/len(matches) * weight) # Calculate the hazard factor as a ratio of hazardous to total asteroids
23
 
24
 
25
  def fetch_nasa():
 
29
  Returns:
30
  Near Earth Objects for the next seven days.
31
  """
32
+
33
  url = "https://api.nasa.gov/neo/rest/v1/feed"
34
 
35
  rawdata = requests.get(
 
44
 
45
  return json.get("near_earth_objects", {}).get("2025-06-11", [])
46
 
47
+ demo = gr.Interface(fn=calc_asteroid_factor, inputs=None, outputs="text")
48
  demo.launch(mcp_server=True)