Algorithm for calculating residential or industrial energy consumption in javascript or typescript

-2

Hello colleagues, I'm creating a component in Angular (5+) where I need an algorithm to perform this calculation of power consumption

In case the power option is selected

I inform you:

  • power

  • Usage (h / day)

  • Rate (R $ / kWh)

  • That should return something like:

    opções escolhidas:
    potencia 0.01 kW
    tarifa 0.77 R$/kWh
    utilização 8 horas por dia
    
    resultados:       
        diário R$  0.06
    
        mensal R$  1.85
    
        anual R$  22.48
    
        decênio R$  224.84
    

    In case of voltage and current: I inform you:

  • Voltage (V)
  • Current (A)
  • Usage (h / day)
  • Rate (R $ / kWh)
  • That should return something like:

    Opções escolhidas:
    potencia 0.05 kW
    tarifa 0.77 R$/kWh
    utilização 8 horas por dia
    
    Resultados:
    Gasto por período
    
    diário R$  0.31
    
    mensal R$  9.24
    
    anual R$  112.42
    
    decênio R$  1,124.20
    
        
    asked by anonymous 26.06.2018 / 23:04

    2 answers

    1

    Power is a physical quantity calculated by the rate of change of energy over the rate of change in time:

    P = ΔE/Δt
    

    Where t is the time instant in which the energy value is E. This "speed" with which the energy varies is called power. To calculate the energy we have:

    P.Δt = ΔE
    

    This variation represents the energy consumption (how much energy has been added to the electrical system of the house, for example). If the energy price is x, we have that the amount paid will be ΔE.x and the time Δt is who will determine if the expense was daily, weekly or monthly.

    The unit of measurement of the result ΔE.x = P.Δt.x will be the product of units of measurement of power, time and energy unit price.

    In the case of being informed of electric current and voltage, we can calculate by Ohm's law the power radiated by the resistor as P=V.i , where V is the voltage (voltage, ddp) and i is the electric current. In this case then ΔE.x = P.Δt.x = V.i.Δt.x

    For 8 hours a day with a price of 0,77 R $ / kWh We have a daily consumption of:

    VALOR = ΔE.0,77 = P.8.0,77 = 6,16.P
    

    If power P is supplied, simply replace it. If voltage and current are supplied, P=V.i . Therefore% w / o must be multiplied by 7 for weekly expenditure, 30 for monthly and 30 * 12 for annual, and so on.

        
    27.06.2018 / 01:16
    0

    Good people, thanks for the help, I managed to do the function in Typescript, follow the code.

    paymentValue() {
     const watt_hour = this.potency * this.hour;
     const kilowatts = (watt_hour / 1000);
     this.kwh = kilowatts;    
     const kilowattsByDay = (kilowatts * this.days);
     this.kwh_days = kilowattsByDay;
     const addedTaxValue = kilowattsByDay * this.tax;    
     this.resultValue = addedTaxValue.toFixed(2);
    }
    

    Basically what I do here is to receive the power values, days of use, hours, convert these data to kwh and do the multiplication by the energy rate per kwh.

    toFixed (2), at the end of the code removes the zeros to the right of the final result of the monthly expense amount per kwh that the customer will pay.

        
    28.06.2018 / 17:36