|
| 1 | +package rtss.ww2losses.helpers; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import rtss.data.bin.Bin; |
| 7 | +import rtss.data.bin.Bins; |
| 8 | +import rtss.data.curves.InterpolatePopulationAsMeanPreservingCurve; |
| 9 | +import rtss.data.curves.TargetResolution; |
| 10 | +import rtss.data.curves.InterpolatePopulationAsMeanPreservingCurve.InterpolationOptions; |
| 11 | +import rtss.data.selectors.Gender; |
| 12 | +import rtss.util.plot.ChartXY; |
| 13 | +import rtss.ww2losses.HalfYearEntries; |
| 14 | +import rtss.ww2losses.HalfYearEntry; |
| 15 | +import rtss.ww2losses.params.AreaParameters; |
| 16 | + |
| 17 | +import static rtss.data.population.projection.ForwardPopulation.years2days; |
| 18 | + |
| 19 | +public class SmoothBirths |
| 20 | +{ |
| 21 | + private final int ndays = years2days(0.5); |
| 22 | + private final double PROMILLE = 1000; |
| 23 | + |
| 24 | + private AreaParameters ap; |
| 25 | + private List<Bin> bins; |
| 26 | + |
| 27 | + public SmoothBirths init(AreaParameters ap, HalfYearEntries<HalfYearEntry> halves) throws Exception |
| 28 | + { |
| 29 | + this.ap = ap; |
| 30 | + this.bins = new ArrayList<>(); |
| 31 | + int nd = 0; |
| 32 | + |
| 33 | + for (HalfYearEntry he : halves) |
| 34 | + { |
| 35 | + if (he.next == null) |
| 36 | + break; |
| 37 | + |
| 38 | + double p1 = he.p_nonwar_with_births.sum(); |
| 39 | + double p2 = he.next.p_nonwar_with_births.sum(); |
| 40 | + double pavg = (p1 + p2) / 2; |
| 41 | + |
| 42 | + double births = ap.CBR_1940_MIDYEAR * pavg / PROMILLE; |
| 43 | + |
| 44 | + bins.add(new Bin(nd, nd + ndays - 1, births)); |
| 45 | + nd += ndays; |
| 46 | + } |
| 47 | + |
| 48 | + return this; |
| 49 | + } |
| 50 | + |
| 51 | + public void calc() throws Exception |
| 52 | + { |
| 53 | + InterpolationOptions options = new InterpolationOptions().usePrimaryCSASRA(true).usePrimarySPLINE(false).useSecondaryRefineYearlyAges(false); |
| 54 | + double[] births = InterpolatePopulationAsMeanPreservingCurve.curve(Bins.bins(bins), "wartime births", TargetResolution.DAILY, 1942, Gender.MALE, options); |
| 55 | + ChartXY.display("Рождения " + ap.area, births); |
| 56 | + // ### |
| 57 | + } |
| 58 | +} |
0 commit comments