Skip to content

Commit 58df027

Browse files
committed
bugfix
add more info in similiarity update pod-definition
1 parent f251af2 commit 58df027

12 files changed

+93
-37
lines changed

DBExportor/POD.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public struct User
3131
private string id_;
3232
public string name;
3333
public string head;
34+
public int anscnt;
35+
public int artcnt;
36+
public int follower;
3437
public string status
3538
{
3639
get { return status_ == UserStatus.empty ? "" : status_.ToString(); }
3740
set { status_ = Enum.TryParse<UserStatus>(value, out var res) ? res : UserStatus.empty; }
3841
}
3942
private UserStatus status_;
40-
public int anscnt;
41-
public int articlecnt;
42-
public int followcnt;
4343
}
4444

4545
[Pod("questions")]
@@ -48,6 +48,8 @@ public struct Question
4848
public uint id;
4949
public string title;
5050
public int[] topics;
51+
public long timeC { get { return timeC_ == uint.MaxValue ? -1L : timeC_; } set { timeC_ = value == -1 ? uint.MaxValue : (uint)value; } }
52+
private uint timeC_;
5153
}
5254

5355
[Pod("articles")]
@@ -59,6 +61,10 @@ public struct Article
5961
private string author_;
6062
public string excerpt;
6163
public int zancnt;
64+
public long timeC { get { return timeC_ == uint.MaxValue ? -1L : timeC_; } set { timeC_ = value == -1 ? uint.MaxValue : (uint)value; } }
65+
private uint timeC_;
66+
public long timeU { get { return timeU_ == uint.MaxValue ? -1L : timeU_; } set { timeU_ = value == -1 ? uint.MaxValue : (uint)value; } }
67+
private uint timeU_;
6268
}
6369

6470
[Pod("topics")]
@@ -77,6 +83,10 @@ public struct Answer
7783
private string author_;
7884
public string excerpt;
7985
public int zancnt;
86+
public long timeC { get { return timeC_ == uint.MaxValue ? -1L : timeC_; } set { timeC_ = value == -1 ? uint.MaxValue : (uint)value; } }
87+
private uint timeC_;
88+
public long timeU { get { return timeU_ == uint.MaxValue ? -1L : timeU_; } set { timeU_ = value == -1 ? uint.MaxValue : (uint)value; } }
89+
private uint timeU_;
8090
}
8191

8292
[Pod("zans", "zanarts")]
@@ -85,6 +95,8 @@ public struct Zan
8595
public string from { get { return from_; } set { from_ = string.Intern(value); } }
8696
private string from_;
8797
public uint to;
98+
public long time { get { return time_ == uint.MaxValue ? -1L : time_; } set { time_ = value == -1 ? uint.MaxValue : (uint)value; } }
99+
private uint time_;
88100
}
89101

90102
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]

DBExportor/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ namespace DBExportor
1515
public class Program
1616
{
1717
public static ushort Port { get; private set; }
18-
public static string Auth { get; private set; } = "171109a";
18+
public static string Auth { get; private set; } = "171112a";
1919
public static string Address { get; private set; }
2020
public static DirectoryInfo DBFolder { get; private set; }
2121
public static void Main(string[] args)
2222
{
2323
Port = (args.Where(p => p.StartsWith("-p")).LastOrDefault()?.Substring(2))
2424
.ToUshort(8913);
25-
var folderpath = args.Where(p => p.StartsWith("-d")).LastOrDefault();
25+
var folderpath = args.Where(p => p.StartsWith("-d")).LastOrDefault()?.Substring(2);
2626
DBFolder = new DirectoryInfo(String.IsNullOrEmpty(folderpath) ? Directory.GetCurrentDirectory() : folderpath);
2727
BuildWebHost(args).Run();
2828
}

DBExportor/Properties/launchSettings.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"profiles": {
33
"DBExportor": {
44
"commandName": "Project",
5+
"commandLineArgs": "-dE:\\Backups",
56
"environmentVariables": {
67
"ASPNETCORE_ENVIRONMENT": "Production"
78
}

ZhiHuExt/ArticlePage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
/**@type {ArtType}*/
8080
const post = Object.values(artdb.Post)[0];
8181
output.topics.push(...post.topics.map(t => new Topic(t.id, t.name)));
82-
const article = new Article(post.slug, post.title, post.author, post.summary.replace(/<[^>]+>/g, ""), post.likesCount,
82+
const article = new Article(post.slug, post.title, post.author, post.likesCount, post.summary.replace(/<[^>]+>/g, ""),
8383
Math.floor(Date.parse(post.publishedTime) / 1000), Math.floor(Date.parse(post.updated) / 1000));
8484
output.articles.push(article);
8585
post.lastestLikers.forEach(theuser =>
@@ -94,7 +94,7 @@
9494
const ath = User.fromRawJson(p.author);
9595
output.users.push(ath);
9696
output.topics.push(...p.topics.map(t => new Topic(t.id, t.name)));
97-
const subart = new Article(p.slug, p.title, ath.id, p.summary.replace(/<[^>]+>/g, ""), p.likesCount,
97+
const subart = new Article(p.slug, p.title, ath.id, p.likesCount, p.summary.replace(/<[^>]+>/g, ""),
9898
Math.floor(Date.parse(p.publishedTime) / 1000));//no updated time
9999
output.articles.push(subart);
100100
});

ZhiHuExt/CommunityRep.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
cell.style.background = "black";
8181
else
8282
cell.style.background = "rgb(0,224,32)";
83-
ContentBase._report("users", user);
83+
//ContentBase._report("users", user);//checkUserState has included thisuser
8484
}
8585

8686
$("body").on("click", "button.Btn-QCheckStatusAll", async function (e)

ZhiHuExt/Export.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
!async function ()
44
{
5-
const auth = "fwAAASLR" + "171109a";
5+
const auth = "fwAAASLR" + "171112a";
66
/**
77
* @param {string} table
88
* @param {number} offset

ZhiHuExt/PeoplePage.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
ContentBase._report("batch", entities);
3939
console.log(entities);
4040
//process user
41-
const selfUser = state.currentUser;
42-
ContentBase.CUR_USER = entities.users.filter(u => u.id === selfUser)[0]
41+
const uid = document.location.pathname.split("/")[2];
42+
if (!uid)
43+
return;
44+
ContentBase.CUR_USER = entities.users.filter(u => u.id === uid)[0]
4345
console.log(ContentBase.CUR_USER);
4446
}
4547
});

ZhiHuExt/analysis.js

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"use strict"
22

3+
var BAN_UID = new Set();
4+
var SPAM_UID = new Set();
5+
36
/**
47
* @template T
58
* @template R
@@ -211,21 +214,32 @@ class Analyse
211214
const uid1 = new Set(uid0);
212215
uid1.delete("");//except anonymous user
213216
const uids = uid1.toArray();
214-
console.log("here [" + uids.length + "] uids");
217+
console.log("Analyse Similarity here [" + uids.length + "] uids");
215218

219+
/**@type {[Promise<Zan[]>, Promise<Zan[]>]}*/
216220
const zanquerys = [db.zans.where("from").anyOf(uids).toArray(), db.zanarts.where("from").anyOf(uids).toArray()];
217-
/**@type {[Zan[], Zan[]]}*/
218221
const [anszan, artzan] = await Promise.all(zanquerys);
219-
console.log("get [" + anszan.length + "] answer records", "get [" + artzan.length + "] article records");
222+
console.log(`get [${anszan.length}] answer records`, `get [${artzan.length}] article records`);
223+
224+
const zancounter = new SimpleBag(anszan.mapToProp("from"));
225+
zancounter.adds(artzan.mapToProp("from"));
220226

221-
const voterbag0 = new SimpleBag(anszan.mapToProp("from"));
222-
voterbag0.adds(artzan.mapToProp("from"));
227+
const zancounter2 = new SimpleBag();
228+
{
229+
/**@type {Set<string>}*/
230+
const banusers = zancounter.toSet().intersection(BAN_UID);
231+
const involvedAnss = new Set(anszan.filter(zan => banusers.has(zan.from)).mapToProp("to"));
232+
anszan.filter(zan => involvedAnss.has(zan.to)).forEach(zan => zancounter2.add(zan.from));
233+
const involvedArts = new Set(artzan.filter(zan => banusers.has(zan.from)).mapToProp("to"));
234+
artzan.filter(zan => involvedArts.has(zan.to)).forEach(zan => zancounter2.add(zan.from));
235+
console.log(`find [${banusers.size}] banned users`, `involve [${involvedAnss.size + involvedArts.size}] objects`);
236+
}
223237

224238
/**@type {number} ln(1~(zan-80)) => [1,9]*/
225239
const minrepeat = Math.minmax(Math.floor(Math.log(Math.max(uids.length - 80, 1))), 1, 9);
226-
const ansbag = new SimpleBag(anszan.mapToProp("to")).above(minrepeat), artbag = new SimpleBag(artzan.mapToProp("to")).above(minrepeat);
227-
const ansset = ansbag.toSet(), artset = artbag.toSet();
228-
console.log("reduce to [" + ansset.size + "] answer records", "get [" + artset.size + "] article records");
240+
const ansset = new SimpleBag(anszan.mapToProp("to")).above(minrepeat).toSet();
241+
const artset = new SimpleBag(artzan.mapToProp("to")).above(minrepeat).toSet();
242+
console.log(`reduce to [${ansset.size}] answer records`, `reduce to [${artset.size}] article records`);
229243

230244
const voterbag = new SimpleBag();
231245
for (let i = 0; i < anszan.length; ++i)
@@ -241,8 +255,9 @@ class Analyse
241255
voterbag.add(zan.from);
242256
}
243257

244-
/**@type {[string, [number, number]][]}*/
245-
const result = voterbag.map((uid, count) => [uid, [count, voterbag0.count(uid)]]);
258+
/**@type {[string, [number, number, number]][]}*/
259+
const result = voterbag.map((uid, count) => [uid, [count, zancounter2.count(uid), zancounter.count(uid)]]);
260+
console.log(`Analyse Similarity finished, threshold [${minrepeat}]`);
246261
return { data: result, limit: minrepeat };
247262
}
248263
}

ZhiHuExt/background.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ Dexie.addons.push(x => x.Collection.prototype.toPropMap = toPropMap);
1818

1919

2020
const db = new Dexie("ZhihuDB");
21-
let BAN_UID = new Set();
22-
let SPAM_UID = new Set();
23-
2421
db.version(1).stores(
2522
{
2623
spams: "id,type",
@@ -315,7 +312,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) =>
315312
const func = request.target === "answer" ? Analyse.getAnsVoters : Analyse.getArtVoters;
316313
func(request.data).then(voters =>
317314
{
318-
const result = checkSpamUser(voters.mapToProp("id"));
315+
const result = checkSpamUser(voters.mapToProp("key"));
319316
result.total = voters.length;
320317
sendResponse(result);
321318
});

ZhiHuExt/content.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ $("body").on("click", "button.Btn-CheckSpam", async function (e)
198198
let total, result;
199199
if (e.shiftKey)
200200
{
201-
result = await ContentBase.checkSpam(type, id);
201+
result = await ContentBase.checkSpam(type, Number(id));
202202
total = result.total;
203203
}
204204
else
@@ -254,7 +254,7 @@ $("body").on("click", "button.Btn-CheckStatus", async function (e)
254254
btn.style.backgroundColor = "rgb(0,224,32)";
255255
$(btn).siblings(".Btn-ReportSpam")[0].style.backgroundColor = "";
256256
}
257-
ContentBase._report("users", user);
257+
//ContentBase._report("users", user);//entity has include this user
258258
});
259259
$("body").on("click", "button.Btn-CheckAllStatus", async function (e)
260260
{
@@ -333,20 +333,20 @@ $("body").on("click", "button.Btn-Similarity", function ()
333333
btns.push(extraArea.children[1]);
334334
});
335335
console.log("detect " + btns.length + " user");
336-
chrome.runtime.sendMessage(msg, /**@param {[string, [number, number]][]} result*/(result) =>
336+
chrome.runtime.sendMessage(msg, /**@param {[string, [number, number, number]][]} result*/(result) =>
337337
{
338338
console.log(result);
339339
const simmap = new Map(result.data);
340340
let maxcnt = 0;
341341
btns.forEach(btn =>
342342
{
343343
const counts = simmap.get(btn.dataset.id);
344-
btn.textContent = counts[0] + "/" + counts[1];
344+
btn.textContent = `${counts[0]}(${counts[1]})/${counts[2]}`;
345345
btn.style.fontSize = "smaller";
346346
btn.style.fontWeight = "bold";
347347
maxcnt = Math.max(maxcnt, counts[0]);
348348
});
349-
thisbtn.textContent = maxcnt + "(" + result.limit + ")";
349+
thisbtn.textContent = `${maxcnt}(${result.limit})`;
350350
thisbtn.style.fontSize = "smaller";
351351
thisbtn.style.fontWeight = "bold";
352352
});

ZhiHuExt/pod.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class Article
7070
* @param {number | string} id
7171
* @param {string} title
7272
* @param {string} author
73-
* @param {string} [excerpt]
7473
* @param {number} [zancnt]
74+
* @param {string} [excerpt]
7575
* @param {number} [timeCreated]
7676
* @param {number} [timeUpdated]
7777
*/
78-
constructor(id, title, author, excerpt, zancnt, timeCreated, timeUpdated)
78+
constructor(id, title, author, zancnt,excerpt, timeCreated, timeUpdated)
7979
{
8080
this.id = Number(id);
8181
this.title = title;
@@ -116,8 +116,8 @@ class Answer
116116
this.id = Number(id);
117117
this.question = Number(quest);
118118
this.author = author;//should not be null
119-
this.zancnt = zancnt == null ? -1 : zancnt;
120119
this.excerpt = excerpt == null ? null : excerpt;
120+
this.zancnt = zancnt == null ? -1 : zancnt;
121121
this.timeC = timeCreated == null ? -1 : timeCreated;
122122
this.timeU = timeUpdated == null ? -1 : timeUpdated;
123123
}
@@ -252,8 +252,8 @@ class APIParser
252252
timeC = Math.floor(Date.parse(obj.publishedTime) / 1000);
253253
if (typeof(timeU) === "string")
254254
timeU = Math.floor(Date.parse(timeU) / 1000);
255-
const art = new Article(obj.id, obj.title, ath.id, _any(obj.excerpt_new, obj.excerptNew),
256-
_any(obj.voteup_count, obj.voteupCount), timeC, timeU);
255+
const art = new Article(obj.id, obj.title, ath.id, _any(obj.voteup_count, obj.voteupCount),
256+
_any(obj.excerpt_new, obj.excerptNew), timeC, timeU);
257257
output.articles.push(art);
258258
return art;
259259
}

ZhiHuExt/utils.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ Array.prototype.filterUnique = function ()
5555
return Array.from(new Set(this));
5656
}
5757

58+
Set.prototype.intersection = function (other)
59+
{
60+
const ret = new Set();
61+
for (const ele of this)
62+
if (other.has(ele))
63+
ret.add(ele);
64+
return ret;
65+
}
5866
Set.prototype.toArray = function ()
5967
{
6068
return Array.from(this);
@@ -261,6 +269,25 @@ class SimpleBag
261269
}
262270
return this;
263271
}
272+
/**
273+
* @template T
274+
* @param {function(T):boolean} [filter]
275+
*/
276+
elements(filter)
277+
{
278+
const keyit = this._map.keys();
279+
if (filter == null)
280+
return Array.from(keyit);
281+
const ret = [];
282+
while (true)
283+
{
284+
const { value, done } = keyit.next();
285+
if (done) break;
286+
if (filter(value))
287+
ret.push(value);
288+
}
289+
return ret;
290+
}
264291
/**
265292
* @template T
266293
* @param {function(T, number): boolean} filtor
@@ -390,8 +417,10 @@ function _sleep(ms)
390417
return new Promise(resolve => setTimeout(resolve, ms));
391418
}
392419
/**
393-
* @param {any[]} array
394-
* @param {Set<any>} set
420+
* @template T
421+
* @param {T[]} array
422+
* @param {Set<T>} set
423+
* @returns {[T[], T[]]} [inside,outside]
395424
*/
396425
function splitInOutSide(array, set)
397426
{

0 commit comments

Comments
 (0)