Commit 80cdaff5 authored by M. Rehan Abbasi's avatar M. Rehan Abbasi
Browse files

fix PredictQosPerTrafficLoad for current time

parent a186c4b4
Loading
Loading
Loading
Loading
+1 −24
Original line number Diff line number Diff line
/*
 * Copyright (c) 2022  InterDigital Communications, Inc
 *
 * Licensed under the Apache License, Version 2.0 (the \"License\");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an \"AS IS\" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * AdvantEDGE V2X Information Service REST API
 *
 * V2X Information Service is AdvantEDGE's implementation of [ETSI MEC ISG MEC030 V2XI API](http://www.etsi.org/deliver/etsi_gs/MEC/001_099/030/02.02.01_60/gs_MEC030v020201p.pdf) <p>[Copyright (c) ETSI 2017](https://forge.etsi.org/etsi-forge-copyright-notice.txt) <p>**Micro-service**<br>[meep-vis](https://github.com/InterDigitalInc/AdvantEDGE/tree/master/go-apps/meep-vis) <p>**Type & Usage**<br>Edge Service used by edge applications that want to get information about radio conditions in the network <p>**Note**<br>AdvantEDGE supports a selected subset of RNI API endpoints (see below) and a subset of subscription types.
 *
 * API version: 2.2.1
 * Contact: AdvantEDGE@InterDigital.com
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package server
package vistrafficmgr

type TimeStamp struct {
	// The nanoseconds part of the time. Time is defined as Unix-time since January 1, 1970, 00:00:00 UTC.
+28 −29
Original line number Diff line number Diff line
@@ -818,33 +818,35 @@ func (tm *TrafficMgr) PredictQosPerTrafficLoad(estimatedTime TimeStamp, inRsrp i

	// Convert unix time to UTC time
	utcTime := time.Unix(int64(estimatedTime.Seconds), int64(estimatedTime.NanoSeconds))
	hour := utcTime.Hour()
	currTime := time.Now()
	hour := int32(utcTime.Hour() + currTime.Hour())
	if hour >= 24 {
		hour = 24 - hour
	}

	// Get time range for DB query
	timeRange := InTimeRange(hour)
	timeRange := inTimeRange(hour)

	// Get predicted load for a given PoA in a desired time slot from the traffic patterns table

	var predictedUserTraffic int
	var predictedUserTraffic int32

	var entry *sql.Rows
	entry, err = tm.db.Query(`
		SELECT "` + timeRange + `" FROM ` + TrafficTable + ` WHERE poa_name = '` + poaName + `'`)
	var rows *sql.Rows
	rows, err = tm.db.Query(`SELECT "` + timeRange + `" FROM ` + TrafficTable + ` WHERE poa_name = '` + poaName + `'`)
	if err != nil {
		log.Error(err)
	}

	entry.Close()
	rows.Close()

	for entry.Next() {
		entry.Scan(&predictedUserTraffic)
	for rows.Next() {
		err = rows.Scan(&predictedUserTraffic)
	}

	err = entry.Err()

	err = rows.Err()
	if err != nil {
		log.Error(err)
		log.Error("Could not find estimated user load in the traffic_patterns table")
		log.Error("Could not find estimated user load in the " + TrafficTable + " table")
		// returning the same values for Rsrp and Rsrq received in request
		return inRsrp, inRsrq, err
	}
@@ -853,7 +855,7 @@ func (tm *TrafficMgr) PredictQosPerTrafficLoad(estimatedTime TimeStamp, inRsrp i
	poaLoad, err := tm.GetPoaLoad(poaName)
	if err != nil {
		log.Error(err)
		log.Error("Could not find PoA load in the traffic_patterns table")
		log.Error("Could not find PoA load in the " + TrafficTable + " table")
		// returning the same values for Rsrp and Rsrq received in request
		return inRsrp, inRsrq, err
	}
@@ -861,24 +863,23 @@ func (tm *TrafficMgr) PredictQosPerTrafficLoad(estimatedTime TimeStamp, inRsrp i
	averageLoad := (poaLoad.ZeroToThree + poaLoad.ThreeToSix + poaLoad.SixToNine + poaLoad.NineToTwelve + poaLoad.TwelveToFifteen + poaLoad.FifteenToEighteen + poaLoad.EighteenToTwentyOne + poaLoad.TwentyOneToTwentyFour) / 8

	// Find reduced signal strength as a function of number of users in the area
	outRsrp, outRsrq, err = FindReducedSignalStrength(inRsrp, inRsrq, predictedUserTraffic, int(averageLoad))

	return
	outRsrp, outRsrq, err = findReducedSignalStrength(inRsrp, inRsrq, predictedUserTraffic, averageLoad)

	return outRsrp, outRsrq, err
}

// Returns the time range as key in the traffic load map against vehicle ETA
func InTimeRange(hour int) (key string) {
func inTimeRange(hour int32) (key string) {

	var TimeWindows = map[string][]int{
		"0000-0300": {0, 1, 2},
		"0300-0600": {3, 4, 5},
		"0600-0900": {6, 7, 8},
		"0900-1200": {9, 10, 11},
		"1200-1500": {12, 13, 14},
		"1500-1800": {15, 16, 17},
		"1800-2100": {18, 19, 20},
		"2100-2400": {21, 22, 23},
	var TimeWindows = map[string][]int32{
		FieldZeroToThree:           {0, 1, 2},
		FieldThreeToSix:            {3, 4, 5},
		FieldSixToNine:             {6, 7, 8},
		FieldNineToTwelve:          {9, 10, 11},
		FieldTwelveToFifteen:       {12, 13, 14},
		FieldFifteenToEighteen:     {15, 16, 17},
		FieldEighteenToTwentyOne:   {18, 19, 20},
		FieldTwentyOneToTwentyFour: {21, 22, 23},
	}

	for key, hours := range TimeWindows {
@@ -895,7 +896,7 @@ func InTimeRange(hour int) (key string) {
// Returns reduced signal strength based on the deviation in predicted user traffic from average user load in that area
// This is a simplistic version, considering only the user load in one particular area
// It will be extended to contain average user load for all active cells and those calculations will be used in further refining the algorithm
func FindReducedSignalStrength(inRsrp int32, inRsrq int32, users int, averageLoad int) (redRsrp int32, redRsrq int32, err error) {
func findReducedSignalStrength(inRsrp int32, inRsrq int32, users int32, averageLoad int32) (redRsrp int32, redRsrq int32, err error) {

	// case: crowded area
	if users > averageLoad {
@@ -910,6 +911,4 @@ func FindReducedSignalStrength(inRsrp int32, inRsrq int32, users int, averageLoa
		// no change in RSRP and RSRQ values
		return inRsrp, inRsrq, nil
	}

	return
}