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, toJSON as weightsToJSON,
fromJSON as weightsFromJSON, fromJSON as weightsFromJSON,
defaultWeights, defaultWeights,
} from "../weights"; } from "../../core/weights";
/** /**
* Parameters for computing TimelineCred * Parameters for computing TimelineCred

View File

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

View File

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

View File

@ -1,7 +1,7 @@
// @flow // @flow
import {type NodeAddressT, type EdgeAddressT} from "../core/graph"; 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 * 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 {NodeAddressT, EdgeAddressT} from "../core/graph";
import type {NodeType, EdgeType} from "./types"; import type {NodeType, EdgeType} from "./types";
import type {Weights as WeightsT, EdgeWeight, NodeWeight} from "./weights"; import type {
import * as Weights from "./weights"; Weights as WeightsT,
EdgeWeight,
NodeWeight,
} from "../core/weights";
import * as Weights from "../core/weights";
import {NodeTrie, EdgeTrie} from "../core/trie"; import {NodeTrie, EdgeTrie} from "../core/trie";
export type NodeWeightEvaluator = (NodeAddressT) => NodeWeight; export type NodeWeightEvaluator = (NodeAddressT) => NodeWeight;

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ import os from "os";
import path from "path"; import path from "path";
import deepFreeze from "deep-freeze"; import deepFreeze from "deep-freeze";
import fs from "fs-extra"; 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"; import {validateToken, type GithubToken} from "../plugins/github/token";
export type PluginName = "git" | "github"; export type PluginName = "git" | "github";

View File

@ -3,7 +3,7 @@
import path from "path"; import path from "path";
import tmp from "tmp"; import tmp from "tmp";
import fs from "fs-extra"; 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 {NodeAddress} from "../core/graph";
import {validateToken} from "../plugins/github/token"; import {validateToken} from "../plugins/github/token";

View File

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

View File

@ -5,7 +5,7 @@ import dedent from "../util/dedent";
import {LoggingTaskReporter} from "../util/taskReporter"; import {LoggingTaskReporter} from "../util/taskReporter";
import type {Command} from "./command"; import type {Command} from "./command";
import * as Common from "./common"; 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 {projectFromJSON} from "../core/project";
import {load} from "../api/load"; import {load} from "../api/load";
import {specToProject} from "../plugins/github/specToProject"; import {specToProject} from "../plugins/github/specToProject";

View File

@ -8,7 +8,7 @@ import {NodeAddress} from "../core/graph";
import {run} from "./testUtil"; import {run} from "./testUtil";
import loadCommand, {help} from "./load"; import loadCommand, {help} from "./load";
import type {LoadOptions} from "../api/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 * as Common from "./common";
import {defaultParams, partialParams} from "../analysis/timeline/params"; import {defaultParams, partialParams} from "../analysis/timeline/params";
import {declaration as githubDeclaration} from "../plugins/github/declaration"; 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 {NodeAddress, EdgeAddress} from "../core/graph";
import {toJSON, fromJSON, defaultWeights, copy} from "./weights"; import {toJSON, fromJSON, defaultWeights, copy} from "./weights";
describe("analysis/weights", () => { describe("core/weights", () => {
it("copy makes a copy", () => { it("copy makes a copy", () => {
const w = defaultWeights(); const w = defaultWeights();
const w1 = copy(w); const w1 = copy(w);

View File

@ -2,7 +2,7 @@
import React from "react"; import React from "react";
import deepEqual from "lodash.isequal"; 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 {type NodeAddressT} from "../core/graph";
import {TimelineCred} from "../analysis/timeline/timelineCred"; import {TimelineCred} from "../analysis/timeline/timelineCred";
import {type TimelineCredParameters} from "../analysis/timeline/params"; 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 {PagerankTable} from "./pagerankTable/Table";
import {WeightConfig} from "../weights/WeightConfig"; import {WeightConfig} from "../weights/WeightConfig";
import {WeightsFileManager} from "../weights/WeightsFileManager"; 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 {Prefix as GithubPrefix} from "../../plugins/github/nodes";
import { import {
createStateTransitionMachine, createStateTransitionMachine,

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import React from "react";
import * as NullUtil from "../../util/null"; import * as NullUtil from "../../util/null";
import {type NodeAddressT, type EdgeAddressT} from "../../core/graph"; 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 NodeType, type EdgeType} from "../../analysis/types";
import type {PluginDeclaration} from "../../analysis/pluginDeclaration"; import type {PluginDeclaration} from "../../analysis/pluginDeclaration";
import {NodeTypeConfig} from "./NodeTypeConfig"; import {NodeTypeConfig} from "./NodeTypeConfig";

View File

@ -5,7 +5,7 @@ import React from "react";
import {FileUploader} from "../../util/FileUploader"; import {FileUploader} from "../../util/FileUploader";
import Link from "../../webutil/Link"; import Link from "../../webutil/Link";
import {MdFileDownload, MdFileUpload} from "react-icons/md"; 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 = {| export type Props = {|
+weights: Weights, +weights: Weights,