Algorithm for calculation of residential or industrial power consumption in javascript or typescript

Asked

Viewed 545 times

-2

Hello colleagues of profession, I am creating a component in Angular(5+) in which I need an algorithm to perform this calculation of energy consumption

In case the power option is selected

I inform the:

  1. potency

  2. Use (h/day)

  3. Rate (R$/kWh)

That I 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 the case of voltage and current: I inform:

  1. Voltage (V)
  2. Current (A)
  3. Use (h/day)
  4. Rate (R$/kWh)

That I 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
  • You can post what you tried?

  • Hi buddy, I’ll post it right here

  • @Eduardovargas posted just below the code I used to solve the problem.

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 at which the energy value is E. This "speed" at which the energy varies is called power. For the calculation of energy we have:

P.Δt = ΔE

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

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

In case of being informed electric current and voltage, we can calculate through 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 daily 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. If voltage and current are provided, P=V.i. Therefore VALOR shall be multiplied by 7 for weekly expenditure, by 30 for monthly and by 30*12 for annual and so on.

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 power values, usage days, hours, convert this 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.