Skip to content

Commit 0282b8e

Browse files
authored
Add files via upload
1 parent 36b9188 commit 0282b8e

File tree

7 files changed

+131
-42
lines changed

7 files changed

+131
-42
lines changed

package-lock.json

+25-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.3",
44
"private": true,
55
"dependencies": {
6-
"graphlabs.core.template": "0.1.41",
6+
"graphlabs.core.template": "^0.1.40",
77
"react": "^16.6.3",
88
"react-dom": "^16.6.3",
99
"react-scripts-ts": "2.14.0"

src/App.tsx

+27-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import './App.css';
22
import * as React from 'react';
33
import { store, TaskTemplate, TaskToolbar, ToolButtonList } from 'graphlabs.core.template';
44
import { Matrix } from './Matrix';
5-
import { IEdgeView, IVertexView } from 'graphlabs.core.template/build/models/graph';
5+
import { IEdgeView } from 'graphlabs.core.template/build/models/graph';
66

77
class App extends TaskTemplate {
88

@@ -20,24 +20,31 @@ class App extends TaskTemplate {
2020
}
2121

2222
calculate() {
23-
const graph = store.getState().graph;
24-
let res = 0;
25-
graph.vertices.forEach((v: IVertexView, index: number) => {
26-
graph.vertices.forEach((w: IVertexView, jndex: number) => {
27-
const e = graph.edges.find((edge: IEdgeView) =>
28-
edge.vertexTwo === v.name && edge.vertexOne === w.name
29-
|| edge.vertexOne === v.name && edge.vertexTwo === w.name);
30-
if (index !== jndex && (this.values[index][jndex] === 0 && e !== void 0
31-
|| this.values[index][jndex] !== 0 && e === void 0)) {
32-
res++;
33-
} else if (index === jndex && this.values[index][jndex] !== 1) {
34-
res++;
23+
const graph = store.getState().graph;
24+
let res = 0;
25+
for (let i = 1; i < graph.vertices.length + 1; i++) {
26+
for (let j = 1; j < graph.edges.length + 1; j++) {
27+
if (this.values[i][j] === 1) {
28+
if ((this.myTuple[j - 1][0] === i - 1) || (this.myTuple[j - 1][1] === i - 1)) {
29+
continue;
30+
}
31+
if ((this.myTuple[j - 1][0] !== i - 1) && (this.myTuple[j - 1][1] !== i - 1)) {
32+
res += 5;
33+
}
34+
}
35+
if (this.values[i][j] === 0) {
36+
if ((this.myTuple[j - 1][0] !== i - 1) && (this.myTuple[j - 1][1] !== i - 1)) {
37+
continue;
3538
}
36-
});
37-
});
38-
// tslint:disable-next-line
39-
console.log(res);
40-
return { success: res === 0, fee: res };
39+
if ((this.myTuple[j - 1][0] === i - 1) || (this.myTuple[j - 1][1] === i - 1)) {
40+
res += 5;
41+
}
42+
}
43+
}
44+
}
45+
46+
console.log(res);
47+
return { success: res === 0, fee: res };
4148
}
4249

4350
make_vec() {
@@ -67,9 +74,9 @@ class App extends TaskTemplate {
6774
}));
6875
}
6976
ToolButtonList.prototype.beforeComplete = beforeComplete.bind(this);
70-
ToolButtonList.prototype.help = () => `В данном задании вы должны заполнить матрицу инцедентности
77+
ToolButtonList.prototype.help = () => `В данном задании вы должны заполнить матрицу инцеденций
7178
в правой части модуля согласно выданному графу.
72-
После заполнения матрицы нажмите кнопку отправки для проверки задания`;
79+
После заполнения матрицы нажмите галочку для проверки задания.`;
7380
return ToolButtonList;
7481
};
7582
return TaskToolbar;

src/Matrix.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ export class Matrix extends Component<Props> {
3636
count++;
3737
return (
3838
<div className="container" key={i}>
39-
<MatrixRow keys={count} length={this.props.columns} edge={this.props.edges}
40-
get={(el, c) => this.get(el, c, i)}>{this.props.children}</MatrixRow>
39+
<MatrixRow
40+
keys={count}
41+
length={this.props.columns}
42+
get={(el, c) => this.get(el, c, i)}
43+
edges={this.props.edges}
44+
/>
4145
</div>);
4246
})}
4347
</div>

src/MatrixCell.tsx

+25-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Props {
99
value: number;
1010
index: number;
1111
get: (e: number) => void;
12+
edges: string;
1213
}
1314

1415
export class MatrixCell extends Component<Props, State> {
@@ -39,14 +40,34 @@ export class MatrixCell extends Component<Props, State> {
3940
});
4041
}
4142
render(): ReactNode {
42-
if (this.props.value === 0) {
43+
if (this.props.value === -2) {
4344
return (
44-
<div style={{ border: '1px double black', background: 'white', padding: '6px' }}>
45-
{this.state.value}
45+
<div style={{ border: '0px double black', textAlign: 'center', width: '40px', minHeight: '10px', background: 'white', padding: '6px' }}>
46+
{this.props.edges}
47+
</div>);
48+
}
49+
if (this.props.value === -3) {
50+
return (
51+
<div style={{ border: '0px double black', textAlign: 'center', width: '40px', minHeight: '10px', background: '', padding: '6px' }}>
52+
{' '}
4653
</div>);
54+
}
55+
if (this.props.value === 0) {
56+
if (this.state.value === -1) {
57+
return (
58+
<div style={{ border: '0px', textAlign: 'center', width: '40px', minHeight: '10px', background: '', padding: '6px' }}>
59+
{' '}
60+
</div>);
61+
} else {
62+
return (
63+
<div style={{ border: '0px double black', textAlign: 'center', width: '40px', minHeight: '10px', background: 'white', padding: '6px' }}>
64+
{this.state.value}
65+
</div>);
66+
}
67+
4768
} else {
4869
return (
49-
<div style={{ border: '1px double black', background: 'white', padding: '6px' }} onClick={this.handler}>
70+
<div style={{ border: '1px double black', textAlign: 'center', width: '40px', minHeight: '10px', background: 'white', padding: '6px' }} onClick={this.handler}>
5071
{this.state.value}
5172
</div>);
5273
}

src/MatrixRow.tsx

+45-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import * as React from 'react';
33
import { MatrixCell } from './MatrixCell';
44

55
interface Props {
6-
edge: [number, number][];
6+
// edge: [number, number][];
77
keys: number;
88
length: number;
99
get: (elem: number, index: number) => void;
10+
edges: [number, number][];
1011
}
1112

1213
export class MatrixRow extends Component<Props> {
@@ -16,19 +17,59 @@ export class MatrixRow extends Component<Props> {
1617
}
1718

1819
render(): ReactNode {
19-
console.log('VEC: ', this.props.edge);
20+
// console.log('VEC: ', this.props.edge);
2021
let flag = -1;
22+
if (this.props.keys === -1) {
23+
console.log('FLG');
24+
return new Array(this.props.length).fill(0).map((e, i) => {
25+
flag++;
26+
console.log('FLAG: ', flag);
27+
if (flag === 0) {
28+
return (
29+
<div key={i} style={{ float: 'left', padding: '2px', cursor: 'pointer' }}>
30+
<MatrixCell
31+
value={-3}
32+
index={this.props.keys}
33+
get={(el: number) => this.get(el, i)}
34+
edges={' '}
35+
/>
36+
</div>);
37+
} else {
38+
console.log('Edges: ', this.props.edges[flag - 1]);
39+
let a = '';
40+
a += this.props.edges[flag - 1][0];
41+
a += ',';
42+
a += this.props.edges[flag - 1][1];
43+
console.log('Edges string: ', a);
44+
return (
45+
<div key={i} style={{ float: 'left', padding: '2px', cursor: 'pointer' }}>
46+
<MatrixCell
47+
value={-2}
48+
index={this.props.keys}
49+
get={(el: number) => this.get(el, i)}
50+
edges={a}
51+
/>
52+
</div>);
53+
}
54+
55+
});
56+
}
2157
return new Array(this.props.length).fill(0).map((e, i) => {
2258
if (flag === 0) {
2359
flag++;
2460
}
2561
if (flag === -1) {
2662
flag++;
2763
}
28-
/*console.log('MR:', this.count, 'KEY:', this.props.keys, 'Ln:', this.props.length);*/
64+
console.log('KEYS:', this.props.keys, 'Ln:', this.props.length);
2965
return (
3066
<div key={i} style={{ float: 'left', padding: '2px', cursor: 'pointer' }}>
31-
<MatrixCell value={flag} index={this.props.keys} get={(el: number) => this.get(el, i)}/>
67+
<MatrixCell
68+
value={flag}
69+
index={this.props.keys}
70+
get={(el: number) => this.get(el, i)}
71+
edges={' '}
72+
/>
3273
</div>);
3374
});
3475
}

tslint.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"jsx-no-lambda": false,
2323
"jsx-no-multiline-js": false,
2424
"label-position": true,
25-
"max-line-length": [ true, 120 ],
25+
"max-line-length": [ false, 120 ],
2626
"member-ordering": [
2727
true,
2828
"public-before-private",
@@ -33,7 +33,7 @@
3333
"no-arg": true,
3434
"no-bitwise": true,
3535
"no-console": [
36-
true,
36+
false,
3737
"log",
3838
"error",
3939
"debug",

0 commit comments

Comments
 (0)