
    r<h                         d dl mZmZmZ  ee      Zd Zd Zej                  ddg      d        Z	edk(  r e        ej                  d	d
       yy)    )Flaskrequestjsonifyc                      t        d       y)z$Mocks loading your trained ML model.zLoading ML model...T)print     5/var/www/sawgrassai.com/machinelearning/ml_service.pymock_load_modelr   	   s    	
 r	   c                 :    | d   }| d   }|dk  ry|dkD  r|dkD  ryy)	a
  
    Mocks running the prediction for a single trip segment.
    
    Features are: [linearity, duration_h, avg_speed_mph]
    
    Logic: If average speed is high (e.g., > 60 MPH) and linearity is high (> 0.85), 
    it's likely Transit. Otherwise, it's local.
    r            ?
Stationaryg      N@g333333?TransitzLocal Destinationr   )features	linearityavg_speed_mphs      r
   mock_classify_tripr      s<     IQKM s 
	)d"2 #r	   z/predict_multi_tripPOST)methodsc                     t        j                  d      } | rd| vst        | d   t              st	        ddi      dfS | d   }g }g }|D ]b  }|j                  dg d      }t        |      }t        d	|d
   dz        }|j                  |       |j                  |t        |d      d       d |rt        |      }nd}t	        t        |d      |d      S )NT)forcetripserrorz:Invalid input structure. Expected JSON with 'trips' array.i  r   )        r   r   r   r   g     R@   )ml_classificationtransit_scorer   )aggregate_transit_scoreclassified_trips)r   get_json
isinstancelistr   getr   minappendroundmax)	datar   
all_scoresr    	trip_datar   classification_labelr   aggregate_scores	            r
   predict_multi_tripr.   )   s    $'D7$&jg.M!]^_adddME J 	==_=  2(; C!t!34-( 	!5"=!4!
 	( j/  #(!#<,  r	   __main__z0.0.0.0i  )hostportN)flaskr   r   r   __name__appr   r   router.   runr   r	   r
   <module>r7      sh    ) )Ho#4  6(3+ 4+\ zGGG& r	   