更改电子表格公式以使其适用于 PHP

发布于 2024-08-16 19:58:53 字数 367 浏览 8 评论 0原文

多年来,我一直使用数学公式来确定留言板的相对活动水平。现在我想在 php 搜索引擎中使用该公式来替换不起作用的 Google 页面排名系统。

使用的数据项是:成员 (B2)、帖子 (D2)、主题 (C2) 和论坛创建日期 (E2)。在电子表格中,基本公式如下所示:

=SUM(((((((B2/E2)+(C2/E2)+(D2/E2)))*0.419)))+((((((B2/C2)+(B2/D2))/2)+(((C2/B2)+(D2/B2))/3)-3.4777)))/7)+0.0017

硬(非生成)数字是我手动计算的数字,以提供似乎提供接近 Alexa 流量排名的结果的输出,并且我每年都会修改它们。输出始终保留到小数点后 4 位。

for years now I have used a math formula to determine relative activity levels for message boards. Now I would like to use that formula in a php search engine to replace the non-functioning Google Page Ranking system.

The data items used are: Members (B2), Posts (D2), Topics (C2), and the Boards creation date (E2). In the spreadsheet the base formula looks like this:

=SUM(((((((B2/E2)+(C2/E2)+(D2/E2)))*0.419)))+((((((B2/C2)+(B2/D2))/2)+(((C2/B2)+(D2/B2))/3)-3.4777)))/7)+0.0017

The hard (non-generated) numbers are numbers I calculated by hand to provide output that seems to provide results close to what would be Alexa Traffic rankings and I modify them each year. The output is always held to 4 decimal places.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虫児飞 2024-08-23 19:58:53

首先,你的方程可以简化很多。现在,您看到了:

=SUM(
    (
        (
            (
                (
                    (
                        (B2/E2) + (C2/E2) + (D2/E2)
                    )
                )
                *
                0.419
            )
        )
    )
    +
    (
        (
            (
                (
                    ( (B2/C2) + (B2/D2) ) / 2
                )
                +
                (
                    ( (C2/B2) + (D2/B2) ) / 3
                )
                -
                3.4777
            )
        )
    )
    /
    7
)
+
0.0017

SUM 函数似乎没用,因为您只有不同的单元格,没有范围。另外,很多括号都可以删除。因此,该函数变成这样:

(
    (
        B2/E2 + C2/E2 + D2/E2
    )
    *
    0.419
    +
    (
        ( B2/C2 + B2/D2 ) / 2
        +
        ( C2/B2 + D2/B2 ) / 3
        -
        3.4777
    )
    /
    7
)
+
0.0017

将其写为单行:

0.0017 + ((B2/E2 + C2/E2 + D2/E2) * 0.419 + ((B2/C2 + B2/D2) / 2 + (C2/B2 + D2/B2) / 3 - 3.4777) / 7)

要使其成为 PHP,请用变量替换单元格地址:

0.0017 + (($members / $date + $topics / $date + $posts / $date) * 0.419 + (($members / $topics + $members / $posts) / 2 + ($topics / $members + $posts / $members) / 3 - 3.4777) / 7)

您可能希望从中创建一个函数,该函数将返回四舍五入到小数点后 4 位的结果:

function ranking($members, $posts, $topics, $date) {
    $ranking = 0.0017 + (($members / $date + $topics / $date + $posts / $date) * 0.419 + (($members / $topics + $members / $posts) / 2 + ($topics / $members + $posts / $members) / 3 - 3.4777) / 7);

    return round($ranking, 4);
}

您可以像这样调用该函数(我不知道日期 E2 是什么样子,因此 30000):

$ranking = ranking(50, 60, 20, 30000);

希望有帮助。

First of all, your equation can be simplified quite a lot. Now, you have this:

=SUM(
    (
        (
            (
                (
                    (
                        (B2/E2) + (C2/E2) + (D2/E2)
                    )
                )
                *
                0.419
            )
        )
    )
    +
    (
        (
            (
                (
                    ( (B2/C2) + (B2/D2) ) / 2
                )
                +
                (
                    ( (C2/B2) + (D2/B2) ) / 3
                )
                -
                3.4777
            )
        )
    )
    /
    7
)
+
0.0017

The SUM function seems useless, as you have only distinct cells, not ranges. Also, a lot of the parenthesis can be removed. Thus, the function becomes this:

(
    (
        B2/E2 + C2/E2 + D2/E2
    )
    *
    0.419
    +
    (
        ( B2/C2 + B2/D2 ) / 2
        +
        ( C2/B2 + D2/B2 ) / 3
        -
        3.4777
    )
    /
    7
)
+
0.0017

Writing that as an one liner:

0.0017 + ((B2/E2 + C2/E2 + D2/E2) * 0.419 + ((B2/C2 + B2/D2) / 2 + (C2/B2 + D2/B2) / 3 - 3.4777) / 7)

To make it PHP, substitute the cell addresses with variables:

0.0017 + (($members / $date + $topics / $date + $posts / $date) * 0.419 + (($members / $topics + $members / $posts) / 2 + ($topics / $members + $posts / $members) / 3 - 3.4777) / 7)

You probably want to make a function out of that that will return the result rounded in 4 decimal places:

function ranking($members, $posts, $topics, $date) {
    $ranking = 0.0017 + (($members / $date + $topics / $date + $posts / $date) * 0.419 + (($members / $topics + $members / $posts) / 2 + ($topics / $members + $posts / $members) / 3 - 3.4777) / 7);

    return round($ranking, 4);
}

And you could call that function like this (I have no idea what the date E2 looks like, thus 30000):

$ranking = ranking(50, 60, 20, 30000);

Hope that helps.

三生池水覆流年 2024-08-23 19:58:53

如果没有有关实际电子表格的更多详细信息,就很难找到可行的解决方案。不过,一般来说,您可能想要编写一个如下所示的函数:

function calculate_ranking($members, $posts, $topics, $creation_date) {
    return ((((((($members/$creation_date)+($topics/$creation_date)+($posts/$creation_date)))*0.419)))+(((((($members/$topics)+($members/$posts))/2)+((($topics/$members)+($posts/$members))/3)-3.4777)))/7)+0.0017;
}

如果您从电子表格中发布一些示例行,那么创建一个有效的解决方案会容易得多。我不确定我是否完全理解您对 sum 函数的调用做了什么,因此我将其从示例中删除了。

Without some more detail about the actual spread sheet, it's very very difficult to come up with a working solution. In general though, you'd probably want to write a function that looks something like this:

function calculate_ranking($members, $posts, $topics, $creation_date) {
    return ((((((($members/$creation_date)+($topics/$creation_date)+($posts/$creation_date)))*0.419)))+(((((($members/$topics)+($members/$posts))/2)+((($topics/$members)+($posts/$members))/3)-3.4777)))/7)+0.0017;
}

If you post some example rows from your spreadsheet it will be much easier to craft a solution that works. I'm not sure I fully understand what your call to the sum function did, so I removed it from my example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文