Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
11 changes: 4 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
<html>
<head>
<meta charset="utf-8">
<title>Scatterwind</title>

<title>Wind Poem</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1">

<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<link href="style.css" rel="stylesheet">
<link href="lib/colorbrewer.css" rel="stylesheet">
<script src="lib/d3.js"></script>
</head>
<body style="padding:0; margin:0; overflow:hidden">
<script src="scatter.js"></script>
<body>
<div id="poem-container"></div>
<script src="script.js"></script>
</body>
</html>
66 changes: 0 additions & 66 deletions scatter.coffee

This file was deleted.

170 changes: 60 additions & 110 deletions script.coffee
Original file line number Diff line number Diff line change
@@ -1,113 +1,63 @@
w = 500
h = 300
padding = 30
maxNumber = Math.random()*1000
numDataPoints = 50
dataset = (([Math.round(Math.random()*maxNumber),Math.round(Math.random()*maxNumber)]) for num in [1..numDataPoints])
# console.log dataset
# Function to fetch and parse wind data
getWindData = ->
d3.text 'https://data.geo.admin.ch/ch.meteoschweiz.messwerte-aktuell/VQHA80.csv', (data) ->
rows = d3.csv.parseRows(data)
header = rows[0].join(';').split(';')
stationIndex = header.indexOf('station/time')
windDirIndex = header.indexOf('dkl010z0')
windSpeedIndex = header.indexOf('fu3010z0')

xScale = d3.scale.linear()
.domain([0, d3.max(dataset,(d)->d[0] )])
.range([padding, w-padding * 2])
for row in rows
rowData = row.join(';').split(';')
if rowData[stationIndex] == 'GVE'
windDirection = parseFloat(rowData[windDirIndex])
windSpeed = parseFloat(rowData[windSpeedIndex])
generatePoem({direction: windDirection, speed: windSpeed})
return

# --- LLM Integration Placeholder ---
# NOTE: The following section is a placeholder for integrating a custom LLM API.
# The current implementation uses a static poem as a fallback because free, no-key LLM APIs
# were not compatible with the sandboxed environment.
#
# To use your own LLM:
# 1. Replace `YOUR_API_ENDPOINT` with your LLM's endpoint URL.
# 2. Add your API key to the request headers.
# 3. Uncomment the `generatePoemWithLLM` function and call it from `generatePoem`.
# 4. Modify the `prompt` and the response handling as needed for your specific API.

yScale = d3.scale.linear()
.domain([0, d3.max(dataset, (d)->d[1])])
.range([h-padding, padding])

xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.ticks(5)

yAxis = d3.svg.axis()
.scale(yScale)
.orient("left")
.ticks(5)


svg = d3.select("body")
.append("svg")
.attr(
width: w
height: h
)

svg.append("clipPath")
.attr("id","chart-area")
.append("rect")
.attr(
x:padding
y:padding
width:w-padding*3
height:h-padding*2
)
svg.append("g")
.attr(
id:"circles"
"clip-path":"url(#chart-area)"
)
.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr(
cx: (d)->xScale(d[0])
cy: (d)->yScale(d[1])
r:2 )

svg.append("g")
.attr(
class: "x axis"
transform: "translate(0,#{h-padding})")
.call(xAxis)

svg.append("g")
.attr(
class: "y axis"
transform: "translate(#{padding},0)")
.call(yAxis)



d3.select("p")
.on("click", ->
numValues = dataset.length
maxNumber = Math.random() * 1000
dataset = (([Math.round(Math.random()*maxNumber),Math.round(Math.random()*maxNumber)]) for num in [1..numValues])

xScale.domain([0, d3.max(dataset,(d)->d[0])])
yScale.domain([0, d3.max(dataset,(d)->d[1])])

svg.selectAll("circle")
.data(dataset)
.transition()
.duration(1000)
.each("start", ->
d3.select(@)
.attr(
fill:"magenta"
r:7
)
)
.attr(
cx: (d)->xScale(d[0])
cy: (d)->yScale(d[1]))
.each("end", ->
d3.select(@)
.transition()
.duration(1000)
.attr(
fill:"black"
r:2
)
)
svg.select(".x.axis")
.transition()
.duration(1000)
.call(xAxis)
svg.select(".y.axis")
.transition()
.duration(1000)
.call(yAxis)
)
# generatePoemWithLLM = (windData) ->
# apiKey = "YOUR_API_KEY"
# apiEndpoint = "YOUR_API_ENDPOINT"
#
# prompt = "Write a short poem about the wind, with a speed of #{windData.speed} km/h and a direction of #{windData.direction} degrees. Make a reference to Zephyr, the Greek god of the west wind."
#
# d3.json(apiEndpoint)
# .header("Authorization", "Bearer " + apiKey)
# .post(JSON.stringify({ prompt: prompt }), (err, response) ->
# if err
# console.error "LLM API Error:", err
# displayPoem(staticPoem) # Fallback to static poem on error
# else
# displayPoem(response.poem) # Adjust based on your API's response structure
# )

# Function to generate a poem.
generatePoem = (windData) ->
# To use the LLM integration, comment out the line below and call generatePoemWithLLM(windData) instead.
poem = """
A gentle breeze, a whispered sigh,
From western skies where Zephyr flies.
The wind vane turns, a silent guide,
As currents drift and softly glide.
"""
displayPoem(poem)


# Function to display the poem
displayPoem = (poem) ->
poemContainer = d3.select("#poem-container")
poemContainer.html(poem)

# Initial call to fetch the data
getWindData()
78 changes: 78 additions & 0 deletions script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Placeholder for styles */