How to conditionally alter search api relevance score?

I must be missing some core concept of search API somehow, but I am stuck. The goal is to alter search API results depending on a flag, like Give flagged products in search API a higher search score? however this time without SOLR, but with database backend instead.

I can see all flagged fields properly indexed, so there is a line that associates the content entity id with the user who flagged, and now I want to increase the relevance score of the results, so that items flagged by the current user are always shown first.

I have hijacked the SearchApiDbService class and I did add the following line in postQuery (I also wonder why this hook does not exist, but that is not relevant for now):

drupal_alter('search_api_db_query_results', $  results, $  query); 

This should allow me to alter the search results right before search_api_db hands them over to the search API right?

So now I use the alter hook as follows:

function mymodule_search_api_db_query_results_alter(&$  results, SearchApiQueryInterface $  query) {   global $  user;   $  uid = $  user->uid;    // Fetch a list of content entities that the user has flagged.   $  drupal_db_q = db_select('search_api_db_MY_FLAG_FIELD_TABLE', 'f')     ->fields('f')     ->condition('value', $  uid);   $  items = $  drupal_db_q->execute()->fetchCol();    // Iterate over results and multiply score of flagged items.   foreach ($  results['results'] as $  key => &$  result) {     if (in_array($  key, $  items)) {       $  result['score'] *= 10;     }   }  dpm($  results);  } 

In $ results I can see that the scores have changed, but the order of the items on my views results page has not, even though I am sorting by relevance.

It has to be something simple, or I am completely misunderstanding how the score value works somehow?

p.s. Since this is conditionally I don’t think altering the search api query directly makes sense because I found no way to boost any field scores there. Directions on how to achieve that are welcome too.

Hackerrank Python | Find the Runner-Up Score

I am trying to complete this hackerrank exercise. The goal is to receive two inputs n (array length) and A (an array of user input) and then print out the second largest value in the array. I came up with this idea and it works in my Google Colab Notebook but on hackerrank it tells me that it could not compile. What is going wrong?

import numpy as np  # read in user values n = int(input()) A = [int(x) for x in input().split()][:n] A = np.asarray(A)  # determine max value to remove it from the array max_value = np.max(A) index = np.argwhere(A == max_value) A_reduced = np.delete(A, index)  print(np.max(A_reduced)) 

github page/ DHH Score Challenge in ruby

I wrote the following code which when executed prints the score of https://github.com/dhh.

require 'typhoeus' require 'json'  class DHHScoreChallenge     def getData         req = Typhoeus.get("https://api.github.com/users/dhh/events/public")         body =  req.body         json_body = JSON.parse(body)    end     def calculateScore json_body        type_and_score = {           :IssuesEvent => 7,           :IssueCommentEvent =>  6,           :PushEvent => 5,           :PullRequestReviewCommentEvent => 4,           :WatchEvent => 3,           :CreateEvent => 2        }        score = 0        json_body.each do |commit|           commit_type =  commit['type']           if type_and_score.has_key? commit_type.to_sym              score = score + type_and_score[commit_type.to_sym]            else              score = score + 1          end        end        score    end     def showScore score       puts "DHH's github score is #{score}"    end end  begin      d = DHHScoreChallenge.new     json_body = d.getData     score = d.calculateScore(json_body)     d.showScore(score) end 

I am a beginner in ruby programming and would like to know the best practices of Ruby. I am trying to include portability, encapsulation, reusability in my code. Please let me know if they have been achieved and if there are any improvements that I can make. Thanks in advance!

Wear levelling score on smartctl does not match TBW claim

I have a small secondary Toshiba RC100 SSD with specified endurance of 120 TB. smartctl reports data units written of about 3% of that. But the wear levelling count(or “Percentage used”) reports at 16%. This is a big discrepancy. From what I can tell, Data Units Written is actual block writes to the device, not logical writes, so write amplification doesn’t explain the discrepancy. What’s going on?

If I score lower when retaking an aptitude test on fiverr.com, does it display that way on my profile?

In fiverr.com (for sellers, at least), there is a “Take a test” option on my profile where I can take aptitude tests for various skills. The test results are displayed on my profile.

I’m allowed to retake the test once after 24hrs, and then again after 3 months, to try to get a higher score.

However, if I get a lower score, will the lower score be displayed on my profile?

Is multi-classing with a lower ability score unbalanced?

The PHB states that the pre-requisites for multi-classing are as follows:

\begin{array}{l|c|c} \textbf{Class} & \textbf{Ability Score} & \textbf{Minimum} \ \hline \text{Barbarian} & \text{Strength} & 13 \ \text{Bard} & \text{Charisma} & 13 \ \text{Cleric} & \text{Wisdom} & 13 \ \text{Druid} & \text{Wisdom} & 13 \ \text{Fighter} & \text{Strength $ or$ Dexterity} & 13 \ \text{Monk} & \text{Dexterity $ and$ Wisdom} & 13 \ \text{Paladin} & \text{Strength $ and$ Charisma} & 13 \ \text{Ranger} & \text{Dexterity $ and$ Wisdom} & 13 \ \text{Rogue} & \text{Dexterity} & 13 \ \text{Sorcerer} & \text{Charisma} & 13 \ \text{Warlock} & \text{Charisma} & 13 \ \text{Wizard} & \text{Intelligence} & 13 \ \end{array}

Would it be unbalanced to allow multi-classing with a lower ability score? The +1 modifier comes at level 12, not 13, so multi-classing at 12 makes more sense to me.

For context: Currently I am playing a Wild Magic Sorcerer (level 3). He has just discovered his magic and set out to share his wonderful gift by cleaning up Fearûn (he is a germaphobe named Pyorelle and makes heavy use of Prestidigitation). He is extremely curious about his magic so he has been reading every book he can find about magic. I never intended to multi-class, but the character has developed to go down a more studied route.

RP-wise, it makes perfect sense for him to take a level of Wizard soon, but mechanics-wise his INT is currently 10. RAW he would need to wait until hitting level 9 to multiclass (increase INT at level 4 and 8, then multiclass at 9), which seems way too long for the amount he has been studying and researching magic for the past level.

As a note: I am working with my DM on options. I am not asking for opinions on whether the DM should/shouldn’t allow an early multiclass. I am more wondering what balance would be broken by allowing multi-class with a lower ability score (but not game-breakingly-low).

Why do some classes gain additional class features when they get an ability score increase but others don’t? [on hold]

Some classes, when they reach a level that gives an ability score increase, don’t usually gain any other class-specific benefits when they reach that level. (Examples: Barbarian, Fighter, Rogue.)

Others, particularly spellcasting classes, will get additional class features (such as extra spell slots or chi) alongside the ability score increase. (Examples: Cleric, Monk, Wizard.)

Why do some classes get extra stuff on top of what the other classes get? Is this balanced in some other way?

I thought that maybe it might have been balanced out by some classes having larger hit dice (so they gain more hit points when they level), but Cleric, Monk and Rogue all have a d8.

spamc -r and spamc give different score

Currently, I have spamassassin running on my system. However, for some reason, lots of spam is coming through that does get tagged when I run the spamc command on the CLI. But also, when running with -R flag it’s different then running without.

When investigating, I found that

spamc < test_mail

gave a different result than;

spamc -R < test_mail

And I can’t figure out where that is coming from. I’ve tried the config files, but there should be no difference because I run it from the CLI as the same user twice.

This is the result of spamc when run via procmail

X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_99,BAYES_999,DKIM_SIGNED,     DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_IMAGE_ONLY_32,HTML_MESSAGE,     LOCAL_RULE50,RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS,T_REMOTE_IMAGE,     URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 

This via spamc via the CLI

Content analysis details:   (7.6 points, 5.0 required)   pts rule name              description ---- ---------------------- --------------------------------------------------  0.0 URIBL_BLOCKED          ADMINISTRATOR NOTICE: The query to URIBL was                             blocked.  See                             http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block                              for more information.                             [URIs: positiveendorsement.com]  1.2 URIBL_ABUSE_SURBL      Contains an URL listed in the ABUSE SURBL                             blocklist                             [URIs: positiveendorsement.com]  3.5 BAYES_99               BODY: Bayes spam probability is 99 to 100%                             [score: 1.0000]  0.2 BAYES_999              BODY: Bayes spam probability is 99.9 to 100%                             [score: 1.0000]  1.3 RCVD_IN_BL_SPAMCOP_NET RBL: Received via a relay in                             bl.spamcop.net                [Blocked - see <https://www.spamcop.net/bl.shtml?45.59.117.90>]  0.0 RCVD_IN_DNSWL_BLOCKED  RBL: ADMINISTRATOR NOTICE: The query to                             DNSWL was blocked.  See                             http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block                              for more information.                             [45.59.117.90 listed in list.dnswl.org]  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record -0.0 SPF_PASS               SPF: sender matches SPF record  0.5 LOCAL_RULE50           BODY: Evil Phrase  0.0 HTML_IMAGE_ONLY_32     BODY: HTML: images with 2800-3200 bytes of                             words  0.0 HTML_MESSAGE           BODY: HTML included in message -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from                             author's domain -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from                             envelope-from domain  0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily                             valid -0.1 DKIM_VALID             Message has at least one valid DKIM or DK signature  1.0 RDNS_DYNAMIC           Delivered to internal network by host with                             dynamic-looking rDNS  0.0 T_REMOTE_IMAGE         Message contains an external image 

And this of spamc -R

Content analysis details:   (13.6 points, 5.0 required)   pts rule name              description ---- ---------------------- --------------------------------------------------  3.5 BAYES_99               BODY: Bayes spam probability is 99 to 100%                             [score: 1.0000]  0.2 BAYES_999              BODY: Bayes spam probability is 99.9 to 100%                             [score: 1.0000]  1.2 URIBL_ABUSE_SURBL      Contains an URL listed in the ABUSE SURBL                             blocklist                             [URIs: positiveendorsement.com]  0.0 URIBL_BLOCKED          ADMINISTRATOR NOTICE: The query to URIBL was                             blocked.  See                             http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block                              for more information.                             [URIs: positiveendorsement.com]  0.0 RCVD_IN_DNSWL_BLOCKED  RBL: ADMINISTRATOR NOTICE: The query to                             DNSWL was blocked.  See                             http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block                              for more information.                             [45.59.117.90 listed in list.dnswl.org]  2.5 URIBL_DBL_SPAM         Contains a spam URL listed in the Spamhaus DBL                             blocklist                             [URIs: positiveendorsement.com]  1.3 RCVD_IN_BL_SPAMCOP_NET RBL: Received via a relay in                             bl.spamcop.net                [Blocked - see <https://www.spamcop.net/bl.shtml?45.59.117.90>]  3.3 RCVD_IN_SBL_CSS        RBL: Received via a relay in Spamhaus SBL-CSS                             [45.59.117.90 listed in zen.spamhaus.org]  0.1 URIBL_CSS_A            Contains URL's A record listed in the Spamhaus CSS                             blocklist                             [URIs: positiveendorsement.com]  0.1 URIBL_CSS              Contains an URL's NS IP listed in the Spamhaus CSS                             blocklist                             [URIs: positiveendorsement.com]  0.0 T_SPF_TEMPERROR        SPF: test of record failed (temperror)  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record  0.5 LOCAL_RULE50           BODY: Evil Phrase  0.0 HTML_IMAGE_ONLY_32     BODY: HTML: images with 2800-3200 bytes of                             words  0.0 HTML_MESSAGE           BODY: HTML included in message -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from                             author's domain -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from                             envelope-from domain  0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily                             valid -0.1 DKIM_VALID             Message has at least one valid DKIM or DK signature  1.0 RDNS_DYNAMIC           Delivered to internal network by host with                             dynamic-looking rDNS  0.0 T_REMOTE_IMAGE         Message contains an external image