-
Notifications
You must be signed in to change notification settings - Fork 1
finalized TDP table for plugin #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/groovy/org/cpuInfoFetcher/ProcessSpecificationsTable.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.cpuinfofetcher | ||
| import org.cpuinfofetcher.utils.Helpers | ||
| import org.dflib.DataFrame | ||
| import java.time.LocalDateTime | ||
| import static org.dflib.Exp.$col | ||
|
|
||
| /** | ||
| * Adds default TDP values to the specifications DataFrame. | ||
| * | ||
| * Groups by 'intended_usage', computes averages for cores, threads, | ||
| * and TDP, adds a row for "unknown" usage, and updates the DataFrame with default entries. | ||
| * | ||
| * @param specifications the input DataFrame | ||
| * @return the updated DataFrame with default TDP values | ||
| */ | ||
| static DataFrame computeDefaultTdps(DataFrame specifications) { | ||
| DataFrame aggregatedDf = specifications.group('intended_usage').agg( | ||
| $col('intended_usage').first().as('intended_usage'), | ||
| $col('cores').castAsInt().avg().as("avg_cores"), | ||
| $col('threads').castAsInt().avg().as("avg_threads"), | ||
| $col('tdp (W)').castAsDouble().avg().as("avg_tdp")) | ||
|
|
||
| DataFrame local_server_rows = aggregatedDf.rows({ it.get('intended_usage') == 'local' || it.get('intended_usage') == 'server' }) | ||
| .select() | ||
|
|
||
| Double unknown_avg_cores = (local_server_rows.sum { it.get('avg_cores') } as Double) / local_server_rows.height() | ||
| Double unknown_avg_threads = (local_server_rows.sum { it.get('avg_threads') } as Double) / local_server_rows.height() | ||
| Double unknown_avg_tdp = (local_server_rows.sum { it.get('avg_tdp') } as Double) / local_server_rows.height() | ||
|
|
||
| aggregatedDf = aggregatedDf.addRow([ | ||
| "intended_usage": "unknown", | ||
| "avg_cores": unknown_avg_cores, | ||
| "avg_threads": unknown_avg_threads, | ||
| "avg_tdp": unknown_avg_tdp | ||
|
|
||
| ]) | ||
|
|
||
| for (int i = 0; i < aggregatedDf.height(); i++) { | ||
| DataFrame row = aggregatedDf.rows(i).select() | ||
| Double avgThreads = row.get("avg_threads", 0) as Double | ||
| Double avgCores = row.get("avg_cores", 0) as Double | ||
| Double avgtdp = row.get("avg_tdp", 0) as Double | ||
| Double computedThreads = avgCores != 0 ? avgThreads / avgCores : 0 | ||
| String intended_usage = row.get("intended_usage", 0) | ||
| specifications = specifications.addRow([ | ||
| 'product_id': "default $intended_usage", | ||
| 'name': "default $intended_usage", | ||
| "time": LocalDateTime.now().toString(), | ||
| 'source': "default $intended_usage", | ||
| "intended_usage": "default $intended_usage", | ||
| 'tdp (W)': Helpers.round(avgtdp), | ||
| "cores": 1, | ||
| "threads": Helpers.round(computedThreads) | ||
| ]) | ||
| } | ||
|
|
||
| return specifications | ||
| } |
26 changes: 26 additions & 0 deletions
26
app/src/main/groovy/org/cpuInfoFetcher/utils/Helpers.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.cpuinfofetcher.utils | ||
|
|
||
| import org.dflib.DataFrame | ||
|
|
||
| static boolean assertEqualDF(DataFrame df1, DataFrame df2) { | ||
| assert df1.size() == df2.size() | ||
| assert df1.getColumnsIndex().toArray() == df2.getColumnsIndex().toArray() | ||
| for (int i = 0; i < df1.width(); i++) { | ||
| for (int j = 0; j < df1.height(); j++) { | ||
| assert df1.get(i, j) == df2.get(i, j) | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| /** | ||
| * Rounds a Double value to two decimal places. | ||
| * | ||
| * @param value the Double to round | ||
| * @return the value rounded to two decimal places | ||
| */ | ||
| static Double round(Double value) { | ||
| Double rounded_value = Math.round(value * 100.0) / 100.0 | ||
| return rounded_value | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/src/test/groovy/org/cpuinfofetcher/ProcessSpecificationsTableTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.cpuinfofetcher | ||
|
|
||
| import org.cpuinfofetcher.utils.Helpers | ||
| import org.dflib.DataFrame | ||
| import spock.lang.Specification | ||
|
|
||
| class ProcessSpecificationsTableTest extends Specification { | ||
|
|
||
| def 'check default tdp computation'() { | ||
| setup: | ||
| DataFrame input = DataFrame | ||
| .foldByColumn("intended_usage", "cores", "threads", "tdp (W)") | ||
| .of("local", "server", "embedded", "local", "server", "embedded", | ||
| 2, 8, 4, 4, 16, 4, | ||
| 2, 16, 8, 4, 32, 8, | ||
| 15.0, 15.0, 1.5, 15.0, 10.0, 1.5) | ||
| DataFrame expected = DataFrame | ||
| .foldByColumn("intended_usage", "cores", "threads", "tdp (W)") | ||
| .of("local", "server", "embedded", "local", "server", "embedded", "default local", "default server", "default embedded", "default unknown", | ||
| 2, 8, 4, 4, 16, 4, 1, 1, 1, 1, | ||
| 2, 16, 8, 4, 32, 8, 1, 2.0, 2.0, 1.8, | ||
| 15.0, 15.0, 1.5, 15.0, 10.0, 1.5, 15.0, 12.5, 1.5, 13.75) | ||
|
|
||
| when: | ||
| DataFrame output = ProcessSpecificationsTable.computeDefaultTdps(input) | ||
|
|
||
| then: | ||
| Helpers.assertEqualDF(expected, output) | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.