diff --git a/Api.php b/Api.php index c6cdda947bfec6f431c6f06c8d1fcf76220b3447..68e3202087c50353704a175915f78509e923b47c 100644 --- a/Api.php +++ b/Api.php @@ -421,7 +421,7 @@ namespace Zaplog { '{title:.{3,55}}', '{markdown:\raw}', '{language:[a-z]{2}}', - '{copyright:(No Rights Apply|All Rights Reserved|No Rights Reserved \(CC0 1\.0\)|Some Rights Reserved \(CC BY-SA 4\.0\))}, null', + '{copyright:(No Rights Apply|All Rights Reserved|No Rights Reserved \(CC0 1\.0\)|Some Rights Reserved \(CC BY-SA 4\.0\))},No Rights Reserved (CC0 1.0)', '{image:\url},null', '{tags:[\w-]{3,55}},null',])) ->add(new Authentication); diff --git a/Plugins/ResponseFilters/get_reactions_link__ContentEmbedderAbstract.php b/Plugins/ResponseFilters/get_reactions_link__VideoEmbedder.php similarity index 92% rename from Plugins/ResponseFilters/get_reactions_link__ContentEmbedderAbstract.php rename to Plugins/ResponseFilters/get_reactions_link__VideoEmbedder.php index da0e9b93713bc8dfb4dd693cb2e9b099769ae3c6..d60b7d5010e6d85f1fba43a520fdd526dd763997 100644 --- a/Plugins/ResponseFilters/get_reactions_link__ContentEmbedderAbstract.php +++ b/Plugins/ResponseFilters/get_reactions_link__VideoEmbedder.php @@ -13,7 +13,7 @@ namespace Zaplog\Plugins\ResponseFilters { // The API has already normalized the url, no need to check all possible patterns // ------------------------------------------------------------------------------ - class get_reactions_link__ContentEmbedderAbstract extends AbstractVideoEmbedder + class get_reactions_link__VideoEmbedder extends AbstractVideoEmbedder { public function __invoke(string $requestUri, stdClass $requestArgs, &$responseData) { diff --git a/ZaplogImport.php b/ZaplogImport.php index 077d0145a9f9d3317daa26b4fdf3595c23712ccd..d29d54024d2a6d77ab6b8494fc2606042568298e 100644 --- a/ZaplogImport.php +++ b/ZaplogImport.php @@ -184,8 +184,6 @@ namespace Zaplog { Db::execute("DELETE FROM links WHERE (tagscount=0 OR votescount=0) AND reactionscount=0"); - Db::execute("CALL calculate_channel_reputations()"); - Db::execute("OPTIMIZE TABLE channels"); Db::execute("OPTIMIZE TABLE links"); Db::execute("OPTIMIZE TABLE tags"); diff --git a/datamodel.sql b/datamodel.sql index 4e71c101a9ddbde29e16b4736b338973a3c57ecd..6742f9baa05c1642aef28ece7364522add14d952 100644 --- a/datamodel.sql +++ b/datamodel.sql @@ -128,13 +128,13 @@ CREATE TABLE links tagscount INT DEFAULT 0, -- the scoring algorithm score INT GENERATED ALWAYS AS ( - + ROUND ( -- no votes no score votescount * -- no tags, no score - IF(tagscount = 0 , 0, 1) * - -- little content, no score - IF(markdown IS NULL OR LENGTH(markdown) < 100, 0, 1) * + IF(tagscount = 0, 0, 1) * + -- longer articles are better + IF(markdown IS NULL OR LENGTH(markdown) < 100, 0, LOG(10, LENGTH(markdown)) - LOG(10, 10)) * -- double score for real articles ( CASE copyright @@ -143,24 +143,20 @@ CREATE TABLE links WHEN 'No Rights Reserved (CC0 1.0)' THEN 2 WHEN 'Some Rights Reserved (CC BY-SA 4.0)' THEN 2 ELSE 1 END - ) * + ) * -- weigh the passive factors, decreasing returns ( - ROUND( - -- more different interactors is better - LOG(10, 1 + uniquereactors * 10) + - -- longer articles are better - LOG(10, 1 + IF(markdown IS NULL, 0, LENGTH(markdown))) + - -- more external reach is better - LOG(10, 1 + uniquereferrers) + - -- more reactions is better - LOG(10, 1 + reactionscount) / 5 + - -- more views always better - LOG(10, 1 + viewscount / 10) - ) + -- more different interactors is better + LOG(10, 1 + uniquereactors * 10) + + -- more external reach is better + LOG(10, 1 + uniquereferrers) + + -- more reactions is better + LOG(10, 1 + reactionscount) / 5 + + -- more views always better + LOG(10, 1 + viewscount / 10) ) - - ), + ) + ), PRIMARY KEY (id), INDEX (channelid), INDEX (published), @@ -279,15 +275,13 @@ DELIMITER ; -- ------------------------------------------------------------------------- DELIMITER // -CREATE PROCEDURE calculate_channel_reputations() +CREATE EVENT calculate_channel_reputations ON SCHEDULE EVERY 24 HOUR DO BEGIN INSERT INTO interactions(type) VALUES('on_reputation_calculated'); - UPDATE channels SET reputation = reputation * 0.9981 + score - prevscore, prevscore = score; + UPDATE channels SET reputation = GREATEST(1, reputation * 0.9981 + score - prevscore), prevscore = score; END // DELIMITER ; -CREATE EVENT calculate_channel_reputations ON SCHEDULE EVERY 24 HOUR DO CALL calculate_channel_reputations(); - -- ------------------------------------------------ -- -- ------------------------------------------------ diff --git a/datamodel_change.sql b/datamodel_change.sql index 9af6582ea94c2ae109d06b8001e27d4e3adf54ca..9f3ef0a7b930fd1953a3d420d121767d6f49b4c7 100644 --- a/datamodel_change.sql +++ b/datamodel_change.sql @@ -1,3 +1,50 @@ USE zaplog; -DROP VIEW trendingtopics; -DROP VIEW trendingchannels; \ No newline at end of file + +DROP PROCEDURE calculate_channel_reputations; + +DROP EVENT calculate_channel_reputations; + +DELIMITER // +CREATE EVENT calculate_channel_reputations ON SCHEDULE EVERY 24 HOUR DO + BEGIN + INSERT INTO interactions(type) VALUES('on_reputation_calculated'); + UPDATE channels SET reputation = GREATEST(1, reputation * 0.9981 + score - prevscore), prevscore = score; + END // +DELIMITER ; + +ALTER TABLE links CHANGE COLUMN score score INT GENERATED ALWAYS AS ( + ROUND ( + -- no votes no score + votescount * + -- no tags, no score + IF(tagscount = 0, 0, 1) * + -- longer articles are better + IF(markdown IS NULL OR LENGTH(markdown) < 100, 0, LOG(10, LENGTH(markdown)) - LOG(10, 10)) * + -- double score for real articles + ( + CASE copyright + WHEN 'No Rights Apply' THEN 1 + WHEN 'All Rights Reserved' THEN 2 + WHEN 'No Rights Reserved (CC0 1.0)' THEN 2 + WHEN 'Some Rights Reserved (CC BY-SA 4.0)' THEN 2 + ELSE 1 END + ) * + -- weigh the passive factors, decreasing returns + ( + -- more different interactors is better + LOG(10, 1 + uniquereactors * 10) + + -- more external reach is better + LOG(10, 1 + uniquereferrers) + + -- more reactions is better + LOG(10, 1 + reactionscount) / 5 + + -- more views always better + LOG(10, 1 + viewscount / 10) + ) + ) +); + +UPDATE channels JOIN links ON channels.id=links.channelid +SET channels.score=channels.score + links.score; + +UPDATE channels SET reputation = 1, prevscore=score; + diff --git a/patman.txt b/patman.txt deleted file mode 100644 index 9daeafb9864cf43055ae93beb0afd6c7d144bfa4..0000000000000000000000000000000000000000 --- a/patman.txt +++ /dev/null @@ -1 +0,0 @@ -test