tools/src/components/Resistor/result.js
2018-08-15 20:08:14 +02:00

70 lines
1.6 KiB
JavaScript

import React, { Component } from 'react';
import {
Row,
Col,
} from 'reactstrap';
class Result extends Component {
state = {};
constructor(props) {
super(props);
this.state = {
powerSource: this.props.powerSource,
powerLed: this.props.powerLed,
ledConsumption: this.props.ledConsumption,
perfectMatch: null,
overR: null,
underR: null,
series: this.props.series,
factors: this.props.factors
};
}
componentDidMount = () => {
const perfectMatch = Math.round( 1000 * ((this.state.powerSource - this.state.powerLed ) / ( this.props.ledConsumption/1000))) / 1000;
let overR = null;
let beforeR = null;
for( let iFactor = 0 ; iFactor < this.state.factors.length ; iFactor += 1 ) {
const factor = this.state.factors[iFactor];
for( let iSerie = 0 ; iSerie < this.state.series.e24.length ; iSerie += 1 ) {
const currentR = this.state.series.e24[iSerie] * factor;
if ( currentR > perfectMatch ) {
overR = currentR;
console.log( overR);
break;
}
beforeR = currentR;
}
if ( overR)
{
break;
}
}
this.setState({perfectMatch, overR, underR: beforeR});
}
render() {
return (
<Row>
<Col xs="12" md="12">
Vous devez mettre une résistance de <strong>{this.state.perfectMatch}&#8486;</strong>.
</Col>
<Col xs="12" md="12">
Les 2 résistances standard les plus proches sont <strong>{this.state.underR}&#8486;</strong> et <strong>{this.state.overR}&#8486;</strong>.
</Col>
</Row>
)
}
}
export default Result