Move weights from analysis to core (#1582)

As part of #1557, I want to move the concept of weights into core, so
that plugins can produce a WeightedGraph rather than raw Graph. This
will allow us to do cred computation directly on the data we get from
the plugins, without recourse to plugin metadata.

Test plan: It's a simple file move; `yarn test` suffices.
This commit is contained in:
Dandelion Mané 2020-01-21 11:56:19 -08:00 committed by GitHub
parent 4d86c538be
commit f70dd7a00f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 28 additions and 24 deletions

View File

@ -6,7 +6,7 @@ import {
toJSON as weightsToJSON,
fromJSON as weightsFromJSON,
defaultWeights,
} from "../weights";
} from "../../core/weights";
/**
* Parameters for computing TimelineCred

View File

@ -9,7 +9,7 @@ import {
DEFAULT_ALPHA,
DEFAULT_INTERVAL_DECAY,
} from "./params";
import {defaultWeights} from "../weights";
import {defaultWeights} from "../../core/weights";
import {NodeAddress} from "../../core/graph";
describe("analysis/timeline/params", () => {

View File

@ -8,7 +8,7 @@ import {sum} from "d3-array";
import * as NullUtil from "../../util/null";
import {Graph, type NodeAddressT, type Edge, type Node} from "../../core/graph";
import {type NodeAndEdgeTypes} from "../types";
import {type Weights} from "../weights";
import {type Weights} from "../../core/weights";
import {type Interval, partitionGraph} from "./interval";
import {
nodeWeightEvaluator,

View File

@ -1,7 +1,7 @@
// @flow
import {type NodeAddressT, type EdgeAddressT} from "../core/graph";
import {type EdgeWeight} from "./weights";
import {type EdgeWeight} from "../core/weights";
/**
* This module defines `NodeType`s and `EdgeType`s, both of which are

View File

@ -2,8 +2,12 @@
import type {NodeAddressT, EdgeAddressT} from "../core/graph";
import type {NodeType, EdgeType} from "./types";
import type {Weights as WeightsT, EdgeWeight, NodeWeight} from "./weights";
import * as Weights from "./weights";
import type {
Weights as WeightsT,
EdgeWeight,
NodeWeight,
} from "../core/weights";
import * as Weights from "../core/weights";
import {NodeTrie, EdgeTrie} from "../core/trie";
export type NodeWeightEvaluator = (NodeAddressT) => NodeWeight;

View File

@ -3,7 +3,7 @@
import deepFreeze from "deep-freeze";
import {NodeAddress, EdgeAddress} from "../core/graph";
import {nodeWeightEvaluator, edgeWeightEvaluator} from "./weightEvaluator";
import {defaultWeights} from "./weights";
import {defaultWeights} from "../core/weights";
describe("src/analysis/weightEvaluator", () => {
describe("nodeWeightEvaluator", () => {

View File

@ -2,7 +2,7 @@
import type {Edge} from "../core/graph";
import type {NodeAndEdgeTypes} from "./types";
import type {Weights} from "./weights";
import type {Weights} from "../core/weights";
import type {EdgeEvaluator} from "./pagerank";
import {nodeWeightEvaluator, edgeWeightEvaluator} from "./weightEvaluator";

View File

@ -2,7 +2,7 @@
import deepFreeze from "deep-freeze";
import {NodeAddress, EdgeAddress} from "../core/graph";
import {type Weights, defaultWeights} from "./weights";
import {type Weights, defaultWeights} from "../core/weights";
import {weightsToEdgeEvaluator} from "./weightsToEdgeEvaluator";
describe("analysis/weightsToEdgeEvaluator", () => {

View File

@ -16,7 +16,7 @@ import {
loadProject,
} from "../core/project_io";
import {makeRepoId} from "../plugins/github/repoId";
import {defaultWeights} from "../analysis/weights";
import {defaultWeights} from "../core/weights";
import {NodeAddress, Graph} from "../core/graph";
import {node} from "../core/graphTestUtil";
import {TestTaskReporter} from "../util/taskReporter";

View File

@ -5,7 +5,7 @@ import os from "os";
import path from "path";
import deepFreeze from "deep-freeze";
import fs from "fs-extra";
import {type Weights, fromJSON as weightsFromJSON} from "../analysis/weights";
import {type Weights, fromJSON as weightsFromJSON} from "../core/weights";
import {validateToken, type GithubToken} from "../plugins/github/token";
export type PluginName = "git" | "github";

View File

@ -3,7 +3,7 @@
import path from "path";
import tmp from "tmp";
import fs from "fs-extra";
import {defaultWeights, toJSON as weightsToJSON} from "../analysis/weights";
import {defaultWeights, toJSON as weightsToJSON} from "../core/weights";
import {NodeAddress} from "../core/graph";
import {validateToken} from "../plugins/github/token";

View File

@ -7,7 +7,7 @@ import dedent from "../util/dedent";
import {LoggingTaskReporter} from "../util/taskReporter";
import type {Command} from "./command";
import * as Common from "./common";
import {defaultWeights} from "../analysis/weights";
import {defaultWeights} from "../core/weights";
import {load} from "../api/load";
import {declaration as discourseDeclaration} from "../plugins/discourse/declaration";
import {type Project, createProject} from "../core/project";

View File

@ -5,7 +5,7 @@ import dedent from "../util/dedent";
import {LoggingTaskReporter} from "../util/taskReporter";
import type {Command} from "./command";
import * as Common from "./common";
import {defaultWeights, fromJSON as weightsFromJSON} from "../analysis/weights";
import {defaultWeights, fromJSON as weightsFromJSON} from "../core/weights";
import {projectFromJSON} from "../core/project";
import {load} from "../api/load";
import {specToProject} from "../plugins/github/specToProject";

View File

@ -8,7 +8,7 @@ import {NodeAddress} from "../core/graph";
import {run} from "./testUtil";
import loadCommand, {help} from "./load";
import type {LoadOptions} from "../api/load";
import {defaultWeights, toJSON as weightsToJSON} from "../analysis/weights";
import {defaultWeights, toJSON as weightsToJSON} from "../core/weights";
import * as Common from "./common";
import {defaultParams, partialParams} from "../analysis/timeline/params";
import {declaration as githubDeclaration} from "../plugins/github/declaration";

View File

@ -4,7 +4,7 @@ import stringify from "json-stable-stringify";
import {NodeAddress, EdgeAddress} from "../core/graph";
import {toJSON, fromJSON, defaultWeights, copy} from "./weights";
describe("analysis/weights", () => {
describe("core/weights", () => {
it("copy makes a copy", () => {
const w = defaultWeights();
const w1 = copy(w);

View File

@ -2,7 +2,7 @@
import React from "react";
import deepEqual from "lodash.isequal";
import {type Weights, copy as weightsCopy} from "../analysis/weights";
import {type Weights, copy as weightsCopy} from "../core/weights";
import {type NodeAddressT} from "../core/graph";
import {TimelineCred} from "../analysis/timeline/timelineCred";
import {type TimelineCredParameters} from "../analysis/timeline/params";

View File

@ -12,7 +12,7 @@ import {type NodeAddressT} from "../../core/graph";
import {PagerankTable} from "./pagerankTable/Table";
import {WeightConfig} from "../weights/WeightConfig";
import {WeightsFileManager} from "../weights/WeightsFileManager";
import {type Weights, defaultWeights} from "../../analysis/weights";
import {type Weights, defaultWeights} from "../../core/weights";
import {Prefix as GithubPrefix} from "../../plugins/github/nodes";
import {
createStateTransitionMachine,

View File

@ -13,7 +13,7 @@ import {
} from "../../analysis/pagerank";
import {TimelineCred} from "../../analysis/timeline/timelineCred";
import type {Weights} from "../../analysis/weights";
import type {Weights} from "../../core/weights";
import {weightsToEdgeEvaluator} from "../../analysis/weightsToEdgeEvaluator";
import {combineTypes} from "../../analysis/pluginDeclaration";

View File

@ -5,7 +5,7 @@ import {StateTransitionMachine, type AppState} from "./state";
import {Graph, NodeAddress} from "../../core/graph";
import {Assets} from "../../webutil/assets";
import {type EdgeEvaluator} from "../../analysis/pagerank";
import {defaultWeights} from "../../analysis/weights";
import {defaultWeights} from "../../core/weights";
import type {
PagerankNodeDecomposition,
PagerankOptions,

View File

@ -4,7 +4,7 @@ import React from "react";
import {WeightSlider, type Props as WeightSliderProps} from "./WeightSlider";
import type {EdgeType} from "../../analysis/types";
import type {EdgeWeight} from "../../analysis/weights";
import type {EdgeWeight} from "../../core/weights";
export class EdgeTypeConfig extends React.Component<{
+weight: EdgeWeight,

View File

@ -3,7 +3,7 @@
import React from "react";
import {WeightSlider} from "./WeightSlider";
import type {NodeType} from "../../analysis/types";
import type {NodeWeight} from "../../analysis/weights";
import type {NodeWeight} from "../../core/weights";
export class NodeTypeConfig extends React.Component<{
+weight: NodeWeight,

View File

@ -4,7 +4,7 @@ import React from "react";
import * as NullUtil from "../../util/null";
import {type NodeAddressT, type EdgeAddressT} from "../../core/graph";
import {type EdgeWeight, type NodeWeight} from "../../analysis/weights";
import {type EdgeWeight, type NodeWeight} from "../../core/weights";
import {type NodeType, type EdgeType} from "../../analysis/types";
import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
import {NodeTypeConfig} from "./NodeTypeConfig";

View File

@ -5,7 +5,7 @@ import React from "react";
import {FileUploader} from "../../util/FileUploader";
import Link from "../../webutil/Link";
import {MdFileDownload, MdFileUpload} from "react-icons/md";
import {type Weights, toJSON, fromJSON} from "../../analysis/weights";
import {type Weights, toJSON, fromJSON} from "../../core/weights";
export type Props = {|
+weights: Weights,