70 lines
1.6 KiB
JavaScript
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}Ω</strong>.
|
|
</Col>
|
|
<Col xs="12" md="12">
|
|
Les 2 résistances standard les plus proches sont <strong>{this.state.underR}Ω</strong> et <strong>{this.state.overR}Ω</strong>.
|
|
</Col>
|
|
</Row>
|
|
)
|
|
}
|
|
}
|
|
|
|
export default Result
|