Terry Zhuo commited on
Commit
7168226
·
1 Parent(s): a238eaa
Files changed (2) hide show
  1. app.py +1 -1
  2. azure_count_ip_data.py +113 -7
app.py CHANGED
@@ -142,7 +142,7 @@ def create_ui():
142
 
143
  with gr.Blocks(title="Battle Count Statistics") as app:
144
  gr.Markdown("# Battle Count Statistics")
145
- gr.Markdown("Displays the count of battles per annotator. 'Total Count' shows all valid battles, while 'Unique Count' shows deduplicated battles based on the first user prompt. Only conversations that pass the vote conditions are counted.")
146
 
147
  with gr.Row():
148
  last_update = gr.Textbox(
 
142
 
143
  with gr.Blocks(title="Battle Count Statistics") as app:
144
  gr.Markdown("# Battle Count Statistics")
145
+ gr.Markdown("Displays the count of battles per annotator. 'Total Count' shows all valid battles, while 'Unique Count' shows deduplicated battles based on the first user prompt. Only conversations that pass the vote conditions are counted, and example prompts are excluded from the unique count.")
146
 
147
  with gr.Row():
148
  last_update = gr.Textbox(
azure_count_ip_data.py CHANGED
@@ -8,6 +8,7 @@ import re
8
  import argparse
9
  from typing import Dict, Set, Tuple, Optional, List, Union
10
  from log_reader import RemoteLogReader
 
11
 
12
  # List of IP addresses we care about
13
  WHITELIST_IPS_DICT = {
@@ -63,6 +64,44 @@ WHITELIST_USERNAMES = [username for usernames in WHITELIST_USERNAMES_DICT.values
63
  logging.basicConfig(level=logging.WARNING)
64
  log = logging.getLogger(__name__)
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  def get_ip_from_jsonl(content: str) -> Optional[str]:
67
  """Extract IP from the first line of a JSONL content"""
68
  try:
@@ -251,11 +290,11 @@ def get_first_user_prompt(content: str) -> Optional[str]:
251
  log.error(f"Error extracting first user prompt: {e}")
252
  return None
253
 
254
- def count_deduplicated_files_per_annotator(reader: 'RemoteLogReader', start_date_str: str = "2025_02_18") -> Dict[str, int]:
255
- """Count deduplicated files per annotator name from the given start date, considering both IP and username
256
 
257
- Deduplication is based on the first user prompt for each annotator.
258
- Only counts conversations that pass the vote conditions.
259
  """
260
  # Convert start date string to datetime
261
  start_date = datetime.strptime(start_date_str, "%Y_%m_%d")
@@ -293,8 +332,11 @@ def count_deduplicated_files_per_annotator(reader: 'RemoteLogReader', start_date
293
  # Extract first user prompt
294
  first_prompt = get_first_user_prompt(content)
295
  if first_prompt:
296
- # Add to set of unique prompts for this annotator
297
- annotator_prompts[annotator_name].add(first_prompt.strip())
 
 
 
298
 
299
  except Exception as e:
300
  log.error(f"Error processing logs for date {date_str}: {e}")
@@ -305,6 +347,18 @@ def count_deduplicated_files_per_annotator(reader: 'RemoteLogReader', start_date
305
  except Exception as e:
306
  log.error(f"Error accessing logs: {e}")
307
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  # Convert sets to counts
309
  return {name: len(prompts) for name, prompts in annotator_prompts.items()}
310
 
@@ -428,6 +482,34 @@ def download_files_by_name(reader: 'RemoteLogReader', start_date_str: str = "202
428
  except Exception as e:
429
  log.error(f"Error accessing logs: {e}")
430
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
  def main():
432
  # Initialize RemoteLogReader
433
  reader = RemoteLogReader()
@@ -436,6 +518,8 @@ def main():
436
  parser = argparse.ArgumentParser(description='Download and organize conversation files by annotator name')
437
  parser.add_argument('--sandbox-check', action='store_true', help='Check for matching sandbox logs')
438
  parser.add_argument('--download', action='store_true', help='Enable file download')
 
 
439
  args = parser.parse_args()
440
 
441
  # Download files if enabled
@@ -443,11 +527,33 @@ def main():
443
  print("\nDownloading files and organizing by annotator name...")
444
  download_files_by_name(reader, check_sandbox=args.sandbox_check)
445
 
 
 
 
 
 
446
  # Count and display statistics
447
  name_counts = count_files_per_annotator(reader)
 
 
448
  print("\nFile counts per annotator:")
 
 
 
 
 
 
 
 
449
  for name, count in sorted(name_counts.items(), key=lambda x: x[1], reverse=True):
450
- print(f"Name: {name:<20} Count: {count}")
 
 
 
 
 
 
 
451
 
452
  if __name__ == "__main__":
453
  main()
 
8
  import argparse
9
  from typing import Dict, Set, Tuple, Optional, List, Union
10
  from log_reader import RemoteLogReader
11
+ import csv
12
 
13
  # List of IP addresses we care about
14
  WHITELIST_IPS_DICT = {
 
64
  logging.basicConfig(level=logging.WARNING)
65
  log = logging.getLogger(__name__)
66
 
67
+ # List of example prompts to exclude from counting
68
+ EXAMPLE_PROMPTS = [
69
+ "使用SVG绘制春节主题的动态图案,包括:1)一个红色的灯笼,带有金色的流苏 2)一个金色的福字,使用书法字体 3)背景添加一些烟花效果 4)在灯笼和福字周围添加一些祥云图案。确保图案布局美观,颜色搭配符合春节传统风格。",
70
+ "SVGを使用して日本の伝統的な和柄パターンを描画してください。1)波紋(さざなみ)模様 2)市松模様 3)麻の葉模様 4)雷文(らいもん)模様を含めてください。色は伝統的な日本の色(藍色、朱色、金色など)を使用し、レイアウトはバランスよく配置してください。",
71
+ "Write HTML with P5.js that simulates 25 particles in a vacuum space of a cylindrical container, bouncing within its boundaries. Use different colors for each ball and ensure they leave a trail showing their movement. Add a slow rotation of the container to give better view of what's going on in the scene. Make sure to create proper collision detection and physic rules to ensure particles remain in the container. Add an external spherical container. Add a slow zoom in and zoom out effect to the whole scene.",
72
+ "Write a Python script to scrape NVIDIA's stock price for the past month using the yfinance library. Clean the data and create an interactive visualization using Matplotlib. Include: 1) A candlestick chart showing daily price movements 2) A line chart with 7-day and 30-day moving averages. Add hover tooltips showing exact values and date. Make the layout professional with proper titles and axis labels.",
73
+ "Write a Python script that uses the Gradio library to create a functional calculator. The calculator should support basic arithmetic operations: addition, subtraction, multiplication, and division. It should have two input fields for numbers and a dropdown menu to select the operation.",
74
+ "Write a Todo list app using React.js. The app should allow users to add, delete, and mark tasks as completed. Include features like filtering tasks by status (completed, active), sorting tasks by priority, and displaying the total number of tasks.",
75
+ "Write a Python script using the Streamlit library to create a web application for uploading and displaying files. The app should allow users to upload files of type .csv or .txt. If a .csv file is uploaded, display its contents as a table using Streamlit's st.dataframe() method. If a .txt file is uploaded, display its content as plain text.",
76
+ "Write a Python function to solve the Trapping Rain Water problem. The function should take a list of non-negative integers representing the height of bars in a histogram and return the total amount of water trapped between the bars after raining. Use an efficient algorithm with a time complexity of O(n).",
77
+ "Create a simple Pygame script for a game where the player controls a bouncing ball that changes direction when it collides with the edges of the window. Add functionality for the player to control a paddle using arrow keys, aiming to keep the ball from touching the bottom of the screen. Include basic collision detection and a scoring system that increases as the ball bounces off the paddle. You need to add clickable buttons to start the game, and reset the game.",
78
+ "Create a financial management Dashboard using Vue.js, focusing on local data handling without APIs. Include features like a clean dashboard for tracking income and expenses, dynamic charts for visualizing finances, and a budget planner. Implement functionalities for adding, editing, and deleting transactions, as well as filtering by date or category. Ensure responsive design and smooth user interaction for an intuitive experience.",
79
+ "Create a Mermaid diagram to visualize a flowchart of a user login process. Include the following steps: User enters login credentials; Credentials are validated; If valid, the user is directed to the dashboard; If invalid, an error message is shown, and the user can retry or reset the password.",
80
+ "Write a Python function to calculate the Fibonacci sequence up to n numbers. Then write test cases to verify the function works correctly for edge cases like negative numbers, zero, and large inputs.",
81
+ "Build an HTML page for a Kanban board with three columns with Vue.js: To Do, In Progress, and Done. Each column should allow adding, moving, and deleting tasks. Implement drag-and-drop functionality using Vue Draggable and persist the state using Vuex.",
82
+ "Develop a Streamlit app that takes a CSV file as input and provides: 1) Basic statistics about the data 2) Interactive visualizations using Plotly 3) A data cleaning interface with options to handle missing values 4) An option to download the cleaned data.",
83
+ "Write an HTML page with embedded JavaScript that creates an interactive periodic table. Each element should display its properties on hover and allow filtering by category (metals, non-metals, etc.). Include a search bar to find elements by name or symbol.",
84
+ "Here's a Python function that sorts a list of dictionaries by a specified key:\n\n```python\ndef sort_dicts(data, key):\n return sorted(data, key=lambda x: x[key])\n```\n\nWrite test cases to verify the function works correctly for edge cases like empty lists, missing keys, and different data types. If you use unittest, please use `unittest.main(argv=['first-arg-is-ignored'], exit=False)` to run the tests.",
85
+ "Create a React component for a fitness tracker that shows: 1) Daily step count 2) Calories burned 3) Distance walked 4) A progress bar for daily goals.",
86
+ "Build a Vue.js dashboard for monitoring server health. Include: 1) Real-time CPU and memory usage graphs 2) Disk space visualization 3) Network activity monitor 4) Alerts for critical thresholds.",
87
+ "Write a C program that calculates and prints the first 100 prime numbers in a formatted table with 10 numbers per row. Include a function to check if a number is prime and use it in your solution.",
88
+ "Write a C++ program that implements a simple calculator using object-oriented programming. Create a Calculator class with methods for addition, subtraction, multiplication, and division. Include error handling for division by zero.",
89
+ "Write a Rust program that generates and prints a Pascal's Triangle with 10 rows. Format the output to center-align the numbers in each row.",
90
+ "Write a Java program that simulates a simple bank account system. Create a BankAccount class with methods for deposit, withdrawal, and balance inquiry. Include error handling for insufficient funds and demonstrate its usage with a few transactions.",
91
+ "Write a Go program that calculates and prints the Fibonacci sequence up to the 50th number. Format the output in a table with 5 numbers per row and include the index of each Fibonacci number.",
92
+ "Write a C program that calculates and prints a histogram of letter frequencies from a predefined string. Use ASCII art to display the histogram vertically.",
93
+ "Write a C++ program that implements a simple stack data structure with push, pop, and peek operations. Demonstrate its usage by reversing a predefined string using the stack.",
94
+ "Write a Rust program that calculates and prints the first 20 happy numbers. Include a function to check if a number is happy and use it in your solution.",
95
+ "Write a Java program that implements a simple binary search algorithm. Create a sorted array of integers and demonstrate searching for different values, including cases where the value is found and not found.",
96
+ "Write a Go program that generates and prints a multiplication table from 1 to 12. Format the output in a neat grid with proper alignment.",
97
+ "hello",
98
+ "Hello",
99
+ "hi",
100
+ "Hi",
101
+ "test",
102
+ "Test"
103
+ ]
104
+
105
  def get_ip_from_jsonl(content: str) -> Optional[str]:
106
  """Extract IP from the first line of a JSONL content"""
107
  try:
 
290
  log.error(f"Error extracting first user prompt: {e}")
291
  return None
292
 
293
+ def get_unique_prompts_per_annotator(reader: 'RemoteLogReader', start_date_str: str = "2025_02_18") -> Dict[str, Set[str]]:
294
+ """Get the set of unique prompts for each annotator from the given start date
295
 
296
+ Only includes conversations that pass the vote conditions.
297
+ Excludes prompts from the predefined list of example prompts.
298
  """
299
  # Convert start date string to datetime
300
  start_date = datetime.strptime(start_date_str, "%Y_%m_%d")
 
332
  # Extract first user prompt
333
  first_prompt = get_first_user_prompt(content)
334
  if first_prompt:
335
+ # Strip whitespace and check if it's not in the example prompts list
336
+ cleaned_prompt = first_prompt.strip()
337
+ if cleaned_prompt and cleaned_prompt not in EXAMPLE_PROMPTS:
338
+ # Add to set of unique prompts for this annotator
339
+ annotator_prompts[annotator_name].add(cleaned_prompt.lower())
340
 
341
  except Exception as e:
342
  log.error(f"Error processing logs for date {date_str}: {e}")
 
347
  except Exception as e:
348
  log.error(f"Error accessing logs: {e}")
349
 
350
+ return dict(annotator_prompts)
351
+
352
+ def count_deduplicated_files_per_annotator(reader: 'RemoteLogReader', start_date_str: str = "2025_02_18") -> Dict[str, int]:
353
+ """Count deduplicated files per annotator name from the given start date, considering both IP and username
354
+
355
+ Deduplication is based on the first user prompt for each annotator.
356
+ Only counts conversations that pass the vote conditions.
357
+ Excludes prompts from the predefined list of example prompts.
358
+ """
359
+ # Get the unique prompts for each annotator
360
+ annotator_prompts = get_unique_prompts_per_annotator(reader, start_date_str)
361
+
362
  # Convert sets to counts
363
  return {name: len(prompts) for name, prompts in annotator_prompts.items()}
364
 
 
482
  except Exception as e:
483
  log.error(f"Error accessing logs: {e}")
484
 
485
+ def export_unique_prompts_to_csv(reader: 'RemoteLogReader', output_file: str, start_date_str: str = "2025_02_18") -> None:
486
+ """Export the unique prompts for each annotator to a CSV file
487
+
488
+ Args:
489
+ reader: RemoteLogReader instance
490
+ output_file: Path to the output CSV file
491
+ start_date_str: The start date in YYYY_MM_DD format
492
+ """
493
+ # Get the unique prompts for each annotator
494
+ annotator_prompts = get_unique_prompts_per_annotator(reader, start_date_str)
495
+
496
+ # Prepare data for CSV
497
+ rows = []
498
+ for annotator, prompts in annotator_prompts.items():
499
+ for prompt in prompts:
500
+ rows.append({
501
+ 'Annotator': annotator,
502
+ 'Prompt': prompt
503
+ })
504
+
505
+ # Write to CSV
506
+ with open(output_file, 'w', newline='', encoding='utf-8') as f:
507
+ writer = csv.DictWriter(f, fieldnames=['Annotator', 'Prompt'])
508
+ writer.writeheader()
509
+ writer.writerows(rows)
510
+
511
+ print(f"Exported {len(rows)} unique prompts to {output_file}")
512
+
513
  def main():
514
  # Initialize RemoteLogReader
515
  reader = RemoteLogReader()
 
518
  parser = argparse.ArgumentParser(description='Download and organize conversation files by annotator name')
519
  parser.add_argument('--sandbox-check', action='store_true', help='Check for matching sandbox logs')
520
  parser.add_argument('--download', action='store_true', help='Enable file download')
521
+ parser.add_argument('--export-prompts', action='store_true', help='Export unique prompts to CSV')
522
+ parser.add_argument('--output-file', default='unique_prompts.csv', help='Output file for unique prompts (default: unique_prompts.csv)')
523
  args = parser.parse_args()
524
 
525
  # Download files if enabled
 
527
  print("\nDownloading files and organizing by annotator name...")
528
  download_files_by_name(reader, check_sandbox=args.sandbox_check)
529
 
530
+ # Export unique prompts if enabled
531
+ if args.export_prompts:
532
+ print(f"\nExporting unique prompts to {args.output_file}...")
533
+ export_unique_prompts_to_csv(reader, args.output_file)
534
+
535
  # Count and display statistics
536
  name_counts = count_files_per_annotator(reader)
537
+ unique_counts = count_deduplicated_files_per_annotator(reader)
538
+
539
  print("\nFile counts per annotator:")
540
+ print(f"{'Name':<20} {'Total':<10} {'Unique':<10} {'Unique %':<10}")
541
+ print("-" * 50)
542
+
543
+ # Calculate totals
544
+ total_sum = sum(name_counts.values())
545
+ unique_sum = sum(unique_counts.values())
546
+
547
+ # Display counts for each annotator
548
  for name, count in sorted(name_counts.items(), key=lambda x: x[1], reverse=True):
549
+ unique = unique_counts.get(name, 0)
550
+ percentage = round((unique / count * 100) if count > 0 else 0, 1)
551
+ print(f"{name:<20} {count:<10} {unique:<10} {percentage:<10}%")
552
+
553
+ # Display totals
554
+ overall_percentage = round((unique_sum / total_sum * 100) if total_sum > 0 else 0, 1)
555
+ print("-" * 50)
556
+ print(f"{'TOTAL':<20} {total_sum:<10} {unique_sum:<10} {overall_percentage:<10}%")
557
 
558
  if __name__ == "__main__":
559
  main()