victor HF Staff commited on
Commit
db727d8
·
1 Parent(s): 62565ae

feat: Exclude error requests from latency stats and plots

Browse files
Files changed (1) hide show
  1. index.html +31 -14
index.html CHANGED
@@ -694,16 +694,23 @@
694
  const successRate = totalRequests > 0 ? ((successfulRequests / totalRequests) * 100).toFixed(1) : 0;
695
 
696
  const validLatencies = rows
 
 
 
 
 
 
697
  .map(r => r.duration_ms)
698
  .filter(d => d !== null && d >= 0);
699
- const avgLatency = validLatencies.length > 0
700
- ? (validLatencies.reduce((a, b) => a + b, 0) / validLatencies.length).toFixed(0)
 
701
  : 0;
702
 
703
- // Calculate median latency per provider for the filtered data
704
  const latencyByProvider = {};
705
- rows.forEach(row => {
706
- if (row.duration_ms !== null && row.duration_ms >= 0) {
707
  if (!latencyByProvider[row.provider_name]) {
708
  latencyByProvider[row.provider_name] = [];
709
  }
@@ -740,9 +747,10 @@
740
  function createLatencyByProviderPlot(rows, selectedModelId) {
741
  const titleContext = selectedModelId === 'all' ? '' : `for ${selectedModelId.split('/').pop()}`;
742
  const dataByProvider = {};
743
- rows.forEach(row => {
 
744
  if (!dataByProvider[row.provider_name]) dataByProvider[row.provider_name] = [];
745
- if (row.duration_ms !== null && row.duration_ms >= 0) {
746
  dataByProvider[row.provider_name].push(row.duration_ms);
747
  }
748
  });
@@ -802,10 +810,11 @@
802
 
803
  function createLatencyByModelPlot(rows) { // Only shown for 'all'
804
  const dataByModel = {};
805
- rows.forEach(row => {
 
806
  const model = row.model_id;
807
  if (!dataByModel[model]) dataByModel[model] = [];
808
- if (row.duration_ms !== null && row.duration_ms >= 0) {
809
  dataByModel[model].push(row.duration_ms);
810
  }
811
  });
@@ -866,8 +875,9 @@
866
  const allProviders = new Set();
867
  const allModels = new Set();
868
 
869
- rows.forEach(row => {
870
- if (row.duration_ms !== null && row.duration_ms >= 0) {
 
871
  const provider = row.provider_name;
872
  const model = row.model_id;
873
  allProviders.add(provider);
@@ -923,9 +933,16 @@
923
  const provider = row.provider_name;
924
  if (!providerStats[provider]) providerStats[provider] = { total: 0, success: 0, errors: 0, latencies: [] };
925
  providerStats[provider].total++;
926
- if (row.response_status_code === 200) providerStats[provider].success++;
927
- else if (row.response_status_code !== null) providerStats[provider].errors++;
928
- if (row.duration_ms !== null && row.duration_ms >= 0) providerStats[provider].latencies.push(row.duration_ms);
 
 
 
 
 
 
 
929
  });
930
 
931
  // Create Header (only if it doesn't exist)
 
694
  const successRate = totalRequests > 0 ? ((successfulRequests / totalRequests) * 100).toFixed(1) : 0;
695
 
696
  const validLatencies = rows
697
+ .map(r => r.duration_ms)
698
+ .filter(d => d !== null && d >= 0); // Keep this filter for null/negative durations
699
+
700
+ // Filter for successful requests *before* calculating average latency
701
+ const successfulRows = rows.filter(r => r.response_status_code === 200);
702
+ const successfulLatencies = successfulRows
703
  .map(r => r.duration_ms)
704
  .filter(d => d !== null && d >= 0);
705
+
706
+ const avgLatency = successfulLatencies.length > 0
707
+ ? (successfulLatencies.reduce((a, b) => a + b, 0) / successfulLatencies.length).toFixed(0)
708
  : 0;
709
 
710
+ // Calculate median latency per provider using only successful requests
711
  const latencyByProvider = {};
712
+ successfulRows.forEach(row => { // Iterate over successful rows only
713
+ if (row.duration_ms !== null && row.duration_ms >= 0) { // Still check for valid duration
714
  if (!latencyByProvider[row.provider_name]) {
715
  latencyByProvider[row.provider_name] = [];
716
  }
 
747
  function createLatencyByProviderPlot(rows, selectedModelId) {
748
  const titleContext = selectedModelId === 'all' ? '' : `for ${selectedModelId.split('/').pop()}`;
749
  const dataByProvider = {};
750
+ // Filter for successful requests before processing
751
+ rows.filter(r => r.response_status_code === 200).forEach(row => {
752
  if (!dataByProvider[row.provider_name]) dataByProvider[row.provider_name] = [];
753
+ if (row.duration_ms !== null && row.duration_ms >= 0) { // Still check for valid duration
754
  dataByProvider[row.provider_name].push(row.duration_ms);
755
  }
756
  });
 
810
 
811
  function createLatencyByModelPlot(rows) { // Only shown for 'all'
812
  const dataByModel = {};
813
+ // Filter for successful requests before processing
814
+ rows.filter(r => r.response_status_code === 200).forEach(row => {
815
  const model = row.model_id;
816
  if (!dataByModel[model]) dataByModel[model] = [];
817
+ if (row.duration_ms !== null && row.duration_ms >= 0) { // Still check for valid duration
818
  dataByModel[model].push(row.duration_ms);
819
  }
820
  });
 
875
  const allProviders = new Set();
876
  const allModels = new Set();
877
 
878
+ // Filter for successful requests before processing
879
+ rows.filter(r => r.response_status_code === 200).forEach(row => {
880
+ if (row.duration_ms !== null && row.duration_ms >= 0) { // Still check for valid duration
881
  const provider = row.provider_name;
882
  const model = row.model_id;
883
  allProviders.add(provider);
 
933
  const provider = row.provider_name;
934
  if (!providerStats[provider]) providerStats[provider] = { total: 0, success: 0, errors: 0, latencies: [] };
935
  providerStats[provider].total++;
936
+ if (row.response_status_code === 200) {
937
+ providerStats[provider].success++;
938
+ // Only add latency for successful requests with valid duration
939
+ if (row.duration_ms !== null && row.duration_ms >= 0) {
940
+ providerStats[provider].latencies.push(row.duration_ms);
941
+ }
942
+ } else if (row.response_status_code !== null) {
943
+ providerStats[provider].errors++;
944
+ }
945
+ // Note: We no longer add latency if the request was not successful (status != 200)
946
  });
947
 
948
  // Create Header (only if it doesn't exist)