Anyone know a way to use wordpress to calculate a median number?

Hi all!

So I'm finally back :slight_smile: And already asking difficult questions :p

Anyway, I'll try and explain what I need, basically there will be 1000's of different items, and 10,000's of the same item.
on each different item, Two separate numbers will entered on each different item and each same item.
Across all numbers entered on all items I need to display a median number of two different categories, i.e number 1 median number 1 and terms median (where terms is the second number). Each item will have a date entered, I need the median number(s) to be filterable based on date.
So is there any plugin that can do all this or get me close? I'm guessing I'm going to have to code it myself, but thought I'd ask before I start :slight_smile:

Thanks! Any suggestions would be greatly appreciated.

Kind Regards
Jack (Coding-Monkey).

  • Kimberly
    • Champion of Loops

    Hello Jack!

    Difficult Questions indeed!

    I'm guessing I'm going to have to code it myself, but thought I'd ask before I start :slight_smile:

    Unfortunately I think you are right on here! I have no idea where to even begin to search for something for this :slight_frown:

    I googled WordPress Median Plugin but no dice hehehe



  • Jack Kitterhing
    • Code Norris

    Hi Kimberly,

    Thanks for the reply :slight_smile:

    I've searched for two days to find something, but alas nothing :slight_frown:

    With this one, maybe wordpress wouldn't be best suited to it anyway, rather a complete custom solution using a web application framework.

    Thanks again!

    Kind Regards
    Jack (Coding-Monkey).

  • mort3n
    • The Crimson Coder

    Hi coding-monkey,

    Trying to get my head around this :slight_smile:

    You have N item_types // (your 1000s)
    For each item_types as item_type
        you have M items // (your 10,000s)
        For each items as item
            you have two numbers
            and one date

    You seek the medians of each of the two numbers across all items, possibly filtered by date.

    If this is correctly understood, then I guess you could create an items table with the structure
    item_type | item_id | first_number | second_number | date
    then use a WP query to select the rows (this is where you filter by date) you need as well as the two cols with numbers and compute the medians of the two numbers.

    Computing medians could be done by writing you own median function in php (Google is your friend :wink: ). One source is a comment on this page

    You should verify correctness of the computations against some trusted source of reference, perhaps

    Hope this gets you started :slight_smile:


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.