2026-04-14-2 full

This commit is contained in:
Hamza-Ayed
2026-04-14 13:28:19 +03:00
parent 581eda1ea8
commit 830b498485
8 changed files with 138 additions and 83 deletions
+2
View File
@@ -6,11 +6,13 @@ import { MapsController } from './maps.controller';
import { RoadSegmentStat } from './road-stat.entity';
import { CandidateRoad } from './candidate-road.entity';
import { RedisModule } from '../common/redis.module';
import { GeocodingModule } from '../geocoding/geocoding.module';
@Module({
imports: [
TypeOrmModule.forFeature([RoadSegmentStat, CandidateRoad]),
RedisModule,
GeocodingModule,
],
controllers: [MapsController],
providers: [MapsService, TrafficGridService],
+28 -1
View File
@@ -6,6 +6,7 @@ import { RoadSpeedProfile } from './road-speed-profile.entity';
import axios from 'axios';
import { RoadSegmentStat } from './road-stat.entity';
import { TrafficGridService } from './traffic-grid.service';
import { GeocodingService } from '../geocoding/geocoding.service';
@Injectable()
export class MapsService {
@@ -15,7 +16,8 @@ export class MapsService {
private configService: ConfigService,
@InjectRepository(RoadSegmentStat)
private roadStatRepo: Repository<RoadSegmentStat>,
private trafficGrid: TrafficGridService
private trafficGrid: TrafficGridService,
private geocodingService: GeocodingService
) {
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
}
@@ -29,6 +31,29 @@ export class MapsService {
// GraphHopper expects [lng, lat] order
const ghPoints = waypoints.map(wp => [wp[1], wp[0]]);
let startName = 'Unknown Location';
let endName = 'Unknown Location';
try {
const startWp = waypoints[0];
const endWp = waypoints[waypoints.length - 1];
const [startRes, endRes] = await Promise.all([
this.geocodingService.reverseGeocode(startWp[0], startWp[1]),
this.geocodingService.reverseGeocode(endWp[0], endWp[1])
]);
const formatName = (r: any) => {
const parts = [r.name_ar || r.name, r.neighbourhood, r.district, r.governorate].filter(Boolean);
// Deduplicate items continuously (e.g. if name is similar to neighborhood)
const uniqueParts = [...new Set(parts)];
return uniqueParts.length > 0 ? uniqueParts.join('، ') : 'Unknown Location';
};
if (startRes && startRes.length > 0) startName = formatName(startRes[0]);
if (endRes && endRes.length > 0) endName = formatName(endRes[0]);
} catch (e) {
console.warn('Geocoding internal error during routing:', e);
}
const payload: any = {
points: ghPoints,
profile: profile,
@@ -79,6 +104,8 @@ export class MapsService {
duration: Math.round(baseDuration),
trafficAwareDuration: Math.round(trafficAwareDuration),
trafficFactor: Math.round(trafficFactor * 100) / 100,
startName,
endName,
points: route.points,
bbox: route.bbox,
alternatives: alternatives // NEW: array of other routes