Results 1 to 2 of 2

Thread: data conversion - kb to mb and seconds to hhmmss

  1. #1
    Contributor
    Join Date
    Apr 2013
    Location
    Warrington
    Posts
    15

    Default data conversion - kb to mb and seconds to hhmmss

    Hi - am trying to convert differing values based on what I refer to as a unit of measure.

    The data I have relates to call usage and is stored in a billing system as follows:

    USAGE_UNITS UNIT_OF_MEASURE
    1024 KB
    120 TEXT
    140 SECONDS
    1000 EVENT
    2048 KB
    I want to convert based on the unit of measure to the following where KB is translated to MB, seconds is translated to hh:mm:ss and SMS/EVENTs are just passed through without any conversion

    USAGE_UNITS NEW_USAGE_UNITS
    1024 1
    120 120
    140 00:02:20
    1000 1000
    3000 2.92
    I have tried to convert using a filter node but have struggled with the formatting for the time based translation, below is what I have so far.

    emit*


    if 'UNIT_OF_MEASURE' == "VOICE" then
    {
    AMOUNT = 'USAGE_UNITS')/60
    }
    else
    if 'UNIT_OF_MEASURE' == "DATA" then
    {
    AMOUNT = 'USAGE_UNITS'/1024


    }
    else
    if 'UNIT_OF_MEASURE' == "SMS" then
    {
    AMOUNT = 'USAGE_UNITS'


    }

    else
    if 'UNIT_OF_MEASURE' == "EVENT" then
    {
    AMOUNT = 'USAGE_UNITS'

    }

    override emit AMOUNT, UNIT_OF_MEASURE

    Any help appreciated.

    Thanks

    Martin

  2. #2
    Lavastorm Employee
    Join Date
    Nov 2012
    Location
    Warrington, UK
    Posts
    232

    Default

    Hi Martin,

    If you want to output all of the new usage amounts in a single field regardless of the unit of measure then you will need to output the field as a string data type (since the hh:mm:ss values are not numeric).

    Here is an example of how it can be achieved:

    Code:
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=5a1aa5547bf642d5
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    USAGE_UNITS:int,UNIT_OF_MEASURE  
    1024,DATA
    120,SMS
    140,VOICE
    1000,EVENT
    3000,DATA
    1,VOICE
    59,VOICE
    61,VOICE
    121,VOICE
    3599,VOICE
    3601,VOICE
    7199,VOICE
    7201,VOICE
    86399,VOICE
    EOX
    editor:XY=220,90
    end:Static_Data
    
    node:Convert_UOM
    bretype:core::Filter
    editor:Label=Convert UOM
    editor:sortkey=5a1aa5b464af05c3
    input:@40fd2c74167f1ca2/=Static_Data.40fe6c55598828e5
    output:@40fd2c7420761db6/=
    prop:Script=<<EOX
     if 'UNIT_OF_MEASURE' == "VOICE" then {
        tempSeconds = 'USAGE_UNITS'
        if(tempSeconds > 86401 or tempSeconds < 0) then {
            abort("VOICE USAGE_UNITS are out of range for record " + str(recordNumber()))
        }
        if tempSeconds >= 3600 then {
            Hours = div(tempSeconds, 3600)
        } else {
            Hours = 0
        }
        tempSeconds = tempSeconds - Hours * 3600
        if tempSeconds >= 60 then {
            Minutes = div(tempSeconds, 60)
        } else {
            Minutes = 0
        }
        Seconds = tempSeconds - Minutes * 60
        AMOUNT = str(time(Hours, Minutes, Seconds))
     } else {
     
    	if 'UNIT_OF_MEASURE' == "DATA" then {
    		AMOUNT = str('USAGE_UNITS'/1024)
    	} else {
    
    		if 'UNIT_OF_MEASURE' == "SMS" then {
    			AMOUNT = str('USAGE_UNITS')
    		} else {
    
    			if 'UNIT_OF_MEASURE' == "EVENT" then {
    				AMOUNT = str('USAGE_UNITS')
    			}
    		}
    	}
    }
    
    
    emit USAGE_UNITS, AMOUNT as "NEW_USAGE_UNITS", UNIT_OF_MEASURE
    EOX
    editor:XY=380,90
    end:Convert_UOM
    Regards,
    Adrian

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •