Skip to content

Commit

Permalink
fix: Add more info on table & temp to 62
Browse files Browse the repository at this point in the history
  • Loading branch information
mrv777 committed Oct 11, 2024
1 parent 51f43bc commit 33a7c57
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bithive",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"author": {
"name": "MrV",
Expand Down
11 changes: 7 additions & 4 deletions src/components/MinerStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Tooltip,
ResponsiveContainer,
} from "recharts";
import { calculateExpectedHashRate } from "@/utils/helpers";

// Add this utility function at the top of the file
const formatDifficulty = (value: number): string => {
Expand Down Expand Up @@ -78,8 +79,10 @@ const MinerStatus: React.FC<MinerStatusProps> = ({ data, ready }) => {
};

// Calculate expected hash rate
const calculatedExpectedHashRate = Math.floor(
data.frequency * ((data.smallCoreCount * data.asicCount) / 1000)
const calculatedExpectedHashRate = calculateExpectedHashRate(
data.frequency,
data.smallCoreCount,
data.asicCount
);
setExpectedHashRate(calculatedExpectedHashRate);

Expand Down Expand Up @@ -207,7 +210,7 @@ const MinerStatus: React.FC<MinerStatusProps> = ({ data, ready }) => {
className={`stat-value ${
data.temp >= 68
? "text-red-500"
: data.temp >= 60
: data.temp >= 62
? "text-yellow-500"
: "text-green-500"
}`}
Expand All @@ -217,7 +220,7 @@ const MinerStatus: React.FC<MinerStatusProps> = ({ data, ready }) => {
<div className="stat-desc">
{data.temp >= 68
? "Warning: Overheating"
: data.temp >= 60
: data.temp >= 62
? "Caution"
: "Healthy"}
</div>
Expand Down
88 changes: 66 additions & 22 deletions src/components/MinerTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from "react";
import { UseQueryResult } from "@tanstack/react-query";
import { calculateExpectedHashRate } from "@/utils/helpers";
import { getDefaultFrequency } from "@/lib/asicDefaults";

interface MinerTableProps {
statusQueries: UseQueryResult<any>[];
Expand Down Expand Up @@ -32,19 +34,23 @@ const MinerTable: React.FC<MinerTableProps> = ({
<table className="table table-compact">
<thead>
<tr>
<th className={visibleColumns.ip ? "" : "hidden"}>
Devices ({devicesWithData}/{hiveData.length})
{devicesWithoutData > 0 && (
<span className="text-xs text-red-500 ml-1">
({devicesWithoutData} offline)
</span>
)}
</th>
<th className={visibleColumns.asicModel ? "" : "hidden"}>ASIC Model</th>
<th className={visibleColumns.ip ? "" : "hidden"}>
Devices ({devicesWithData}/{hiveData.length})
{devicesWithoutData > 0 && (
<span className="text-xs text-red-500 ml-1">
({devicesWithoutData} offline)
</span>
)}
</th>
<th className={visibleColumns.asicModel ? "" : "hidden"}>
ASIC Model
</th>
<th className={visibleColumns.bestDiff ? "" : "hidden"}>Best Diff</th>
<th className={visibleColumns.hashRate ? "" : "hidden"}>Hash Rate</th>
<th className={visibleColumns.temp ? "" : "hidden"}>Temp</th>
<th className={visibleColumns.frequency ? "" : "hidden"}>Frequency</th>
<th className={visibleColumns.frequency ? "" : "hidden"}>
Frequency
</th>
<th className={visibleColumns.voltage ? "" : "hidden"}>Voltage</th>
<th className={visibleColumns.power ? "" : "hidden"}>Power</th>
<th className={visibleColumns.delete ? "" : "hidden"}>Actions</th>
Expand All @@ -65,33 +71,50 @@ const MinerTable: React.FC<MinerTableProps> = ({
<td className={visibleColumns.bestDiff ? "" : "hidden"}>
{query.data ? (
<>
{query.data.bestSessionDiff || "N/A"}{" "}
<span className="tooltip cursor-help" data-tip="All Time">
<div>{query.data.bestSessionDiff || "N/A"}</div>
<div className="tooltip cursor-help text-sm text-gray-500" data-tip="All Time">
({query.data.bestDiff || "N/A"})
</span>
</div>
</>
) : (
"N/A"
)}
</td>
<td className={visibleColumns.hashRate ? "" : "hidden"}>
{query.data ? `${query.data.hashRate.toFixed(2)} Gh/s` : "N/A"}
<div>{query.data ? `${query.data.hashRate.toFixed(2)} Gh/s` : "N/A"}</div>
<div className="tooltip cursor-help text-sm text-gray-500" data-tip="Expected Hash Rate">
{query.data
? `${calculateExpectedHashRate(
query.data.frequency,
query.data.smallCoreCount,
query.data.asicCount
).toFixed(0)} Gh/s`
: "N/A"}
</div>
</td>
<td
className={`${visibleColumns.temp ? "" : "hidden"} ${
query.data?.temp
? query.data?.temp >= 68
? "text-red-500"
: query.data?.temp >= 60
: query.data?.temp >= 62
? "text-yellow-500"
: "text-green-500"
: ""
}`}
>
{query.data ? `${query.data.temp}°C` : "N/A"}
<div>{query.data ? `${query.data.temp}°C` : "N/A"}</div>
{query.data?.temp >= 68
? "Warning: Overheating"
: query.data?.temp >= 62
? "Caution"
: "Healthy"}
</td>
<td className={visibleColumns.frequency ? "" : "hidden"}>
{query.data ? `${query.data.frequency} MHz` : "N/A"}
<div>{query.data ? `${query.data.frequency} MHz` : "N/A"}</div>
<div className="tooltip cursor-help text-sm text-gray-500" data-tip="Default Frequency">
{getDefaultFrequency(query.data?.ASICModel || "").toFixed(0)} MHz
</div>
</td>
<td
className={`${visibleColumns.voltage ? "" : "hidden"} ${
Expand All @@ -104,16 +127,37 @@ const MinerTable: React.FC<MinerTableProps> = ({
: ""
}`}
>
{query.data
? `${(query.data.voltage / 1000).toFixed(2)}V`
<div>
{query.data
? `${(query.data?.voltage / 1000).toFixed(2)}V`
: "N/A"}
</div>
{query.data?.voltage > 4900
? "Healthy"
: query.data?.voltage > 4800
? "Caution"
: "Under Voltage"}
</td>
<td className={visibleColumns.power ? "" : "hidden"}>
{query.data ? `${query.data.power.toFixed(2)}W` : "N/A"}
{query.data?.power ?
<>
<div>
{query.data.power.toFixed(2)}W
</div>
<div className="text-sm text-gray-500">
{(
(query.data.power / (query.data.hashRate ?? 1)) *
1000
).toFixed(2)} J/Th
</div>
</>
: "N/A"}
</td>
<td className={visibleColumns.delete ? "" : "hidden"}>
<button
onClick={() => { removeFromHive(hiveData[index]); }}
onClick={() => {
removeFromHive(hiveData[index]);
}}
className="btn btn-error btn-xs"
>
Delete
Expand All @@ -126,4 +170,4 @@ const MinerTable: React.FC<MinerTableProps> = ({
);
};

export default MinerTable;
export default MinerTable;
20 changes: 19 additions & 1 deletion src/lib/asicDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,22 @@ export const coreVoltageOptions: Record<string, DropdownOption[]> = {
{ name: '1250', value: 1250 },
{ name: '1300', value: 1300 },
],
};
};

export function getDefaultFrequency(model: string): number {
const options = frequencyOptions[model];
if (!options) {
throw new Error(`No frequency options found for model ${model}`);
}
const defaultOption = options.find(option => option.name.includes('default'));
return defaultOption ? defaultOption.value : options[0].value;
}

export function getDefaultCoreVoltage(model: string): number {
const options = coreVoltageOptions[model];
if (!options) {
throw new Error(`No core voltage options found for model ${model}`);
}
const defaultOption = options.find(option => option.name.includes('default'));
return defaultOption ? defaultOption.value : options[0].value;
}
8 changes: 8 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ export function parseDifficulty(diffString: string): number {

return numericValue * (multipliers[suffix.toUpperCase()] || 1);
}

export const calculateExpectedHashRate = (
frequency: number,
smallCoreCount: number,
asicCount: number
): number => {
return Math.floor(frequency * ((smallCoreCount * asicCount) / 1000));
};

0 comments on commit 33a7c57

Please sign in to comment.