9.2.2 • Published 5 years ago

@dra2020/dra-score v9.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

dra-score

This is the scoring package that we use in Dave's Redistricting. It takes the profile of a plan in and returns a scorecard.

We've made it public, so you can see exactly how we calculate each metric.

Exports

Scorer Class

Use the Scorer class to score the profile for a set of districts yielding a scorecard.

export declare class Scorer {
  constructor() {}
  score(profile: Profile): Scorecard;
}

Profile type

The Profile and subordinate type defines the abstract of the full set of data for a set of districts that you need to score them.

export declare type Profile = {
  state: string;                       // Two-character state abbreviation (e.g., NC)
  planName: string;
  nDistricts: number;
  nCounties: number;
  legislativeDistricts: boolean;
  populationProfile: PopulationProfile;
  compactnessProfile: ShapeProfile;
  splittingProfile: SplittingProfile;
  partisanProfile: PartisanProfile;
  demographicProfile: DemographicProfile
}

export declare type PopulationProfile = {
  totalPopByDistrict: totalPopByDistrict;
  targetSize: number
}
export declare type totalPopByDistrict = number[];

export declare type ShapeProfile = {
  geometryByDistrict: geometryByDistrict;
}
export declare type geometryByDistrict = number[][];

export declare type SplittingProfile = {
  countyPopByDistrict: CxD;
}
export declare type CxD = number[][];

export declare type PartisanProfile = {
  statewideVf: number;
  vfArray: VfArray;
}
export declare type VfArray = number[];

export declare type DemographicProfile = {
  stateMfArray: MfArray;
  mfArrayByDistrict: MfArray[];
}
export declare type MfArray = number[];

Scorecard type

The Scorecard and subordinate types together describe all the analytics computed for a set of districts.

export declare type Scorecard = {
  partisan: PartisanScorecard;
  minority: MinorityScorecard;
  compactness: CompactnessScorecard;
  splitting: SplittingScorecard;
  populationDeviation: PopulationScorecard;
  details: Dict;
}

export declare type PartisanScorecard = {
  bias: Bias;
  impact: Impact;
  responsiveness: Responsiveness;
  dSVpoints: SVpoint[];
  rSVpoints: SVpoint[];
  averageDVf: number | undefined;
  averageRVf: number | undefined;
  details: Dict;
}

export declare type Bias = {
  bestS: number;
  bestSf: number;
  estS: number;
  estSf: number;
  deviation: number;
  score: number;

  tOf?: number;
  fptpS?: number;
  bS50?: number;
  bV50?: number;
  decl?: number | undefined;
  rvPoints?: rVpoints;
  gSym?: number;
  gamma?: number;
  eG?: number;
  bSV?: number;
  prop?: number;
  mMs?: number;
  mMd?: number;
  lO?: number | undefined;
}

export declare type Impact = {
  unearnedS: number;
  score: number;
}

export declare type Responsiveness = {
  bigR?: number | undefined;
  littleR?: number | undefined;
  mIR?: number | undefined;
  rD?: number;
  rDf?: number;

  cSimple: number;
  cD: number;
  cDf: number;
  score: number;
}

export declare type SVpoint = {
  v: number;  // A fraction [0.0–1.0]
  s: number   // A fraction [0.0–1.0]
};

export declare type rVpoints = {
  Sb: number,
  Ra: number,
  Rb: number,
  Va: number,
  Vb: number
}

export declare type MinorityScorecard = {
  pivotByDemographic: number[][];
  opportunityDistricts: number;
  coalitionDistricts: number;
  score: number;
  details: Dict;
}

export declare type CompactnessScorecard = {
  score: number;
  reock: Measurement;
  polsby: Measurement;
  details: Dict;
};

export declare type SplittingScorecard = {
  score: number;
  county: Measurement;
  district: Measurement;
  details: Dict;
};

export declare type PopulationScorecard = Measurement;

export declare type Measurement = {
  raw: number;
  normalized: number;
  notes: Dict;
}

export declare type Dict = {[key: string]: any};

Enums

The Demographic and PivotField enums define how to access the rows and columns, respectively, of the pivot table in the MinorityScorecard type (above).

export declare const enum Demographic
{
  Minority,                            // 'Minority'
  Black,                               // 'Black'
  Hispanic,                            // 'Hispanic'
  Pacific,                             // 'Pacific'
  Asian,                               // 'Asian'
  Native                               // 'Native'
}
export declare const enum PivotField
{
  L35_40,
  L40_45,
  L45_50,
  L50_55,
  L55_60,
  L60Plus,
  VAPPct,    // Statewide VAP %
  PropSeats  // Proportional # of seats for VAP %
}

estSeatProbability

This routine takes a Democratic seat share (Vf), by convention, and returns the probability that Democrats will win the seat.

export declare function estSeatProbability(Vf: number): number;

This can be useful in visualization scenarios.

Versions

  • 9.1.2 -- First public version

Repo contents

There are three packages that are part of this repo:

  1. src: building dra-score.bundle.js, the production code
  2. cli: building cli.cs, a command line utility to run dra-score
  3. test: automated test code run by jest

Developing in this repo

npm install install all dependencies

npm run build build all bundles

npm run test run automated jest tests

Build status for master branch

CircleCI

9.2.2

5 years ago

9.2.1

5 years ago

9.2.0

5 years ago

9.1.3

5 years ago

9.1.2

5 years ago

9.1.1

5 years ago

9.1.0

5 years ago

9.0.1

5 years ago

9.0.0

5 years ago

8.1.2

5 years ago

8.1.1

5 years ago

8.1.0

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

7.1.1

5 years ago

7.1.0

5 years ago

7.0.0

5 years ago

6.0.0

5 years ago

5.0.0

5 years ago

4.7.0

5 years ago

4.6.3

5 years ago

4.6.2

5 years ago

4.6.1

5 years ago

4.6.0

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.4

5 years ago

4.4.3

5 years ago

4.4.2

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.7

5 years ago

4.1.6

5 years ago

4.1.5

5 years ago

4.1.4

5 years ago

4.1.3

5 years ago

4.1.2

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.2

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago