Commit 34f65d52 authored by Christopher Silva's avatar Christopher Silva

move the library to spreadsheet_core and make spreadsheet for the actual application

parent 86d46690
......@@ -376,6 +376,14 @@ dependencies = [
[[package]]
name = "spreadsheet"
version = "0.1.0"
dependencies = [
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"spreadsheet_core 0.1.0",
]
[[package]]
name = "spreadsheet_core"
version = "0.1.0"
dependencies = [
"anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package]
name = "spreadsheet"
version = "0.1.0"
authors = ["csos95 <csoscss@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust_decimal = "1.0.3"
anyhow = "1.0.25"
pest = "2.1.2"
pest_derive = "2.1.0"
petgraph = "0.4.13"
rayon = "1.2.1"
[workspace]
members = [
"spreadsheet",
"spreadsheet_core",
]
This diff is collapsed.
[package]
name = "spreadsheet"
version = "0.1.0"
authors = ["csos95 <csoscss@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
spreadsheet_core = { path = "../spreadsheet_core" }
anyhow = "1.0.25"
use anyhow::Result;
use spreadsheet_core::workbook::Workbook;
fn main() -> Result<()> {
let mut workbook = Workbook::new();
let sheet = workbook.add_sheet("Test".into());
for i in 0..200 {
for j in 0..200 {
sheet.write_text(i, j, format!("text {} {}", i, j)).unwrap();
}
}
sheet.process_changes()?;
println!("range r0c0:r9c9: {:?}", sheet.render_range(0, 0, 10, 10));
Ok(())
}
This diff is collapsed.
[package]
name = "spreadsheet_core"
version = "0.1.0"
authors = ["csos95 <csoscss@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust_decimal = "1.0.3"
anyhow = "1.0.25"
pest = "2.1.2"
pest_derive = "2.1.0"
petgraph = "0.4.13"
rayon = "1.2.1"
#[macro_use]
extern crate pest_derive;
pub mod cell;
pub mod formula;
pub mod function;
pub mod sheet;
pub mod workbook;
#[cfg(test)]
mod test {
use std::str::FromStr;
use anyhow::Result;
use rust_decimal::prelude::*;
use rust_decimal::Decimal;
use crate::function;
use crate::workbook::Workbook;
#[test]
fn test_all() -> Result<()> {
let mut workbook = Workbook::new();
let sheet = workbook.add_sheet("Test".into());
println!("inserting cells");
for i in 0..200 {
for j in 0..200 {
sheet.write_text(i, j, format!("text {} {}", i, j)).unwrap();
}
}
sheet.process_changes()?;
println!("rendering ranges");
for i in 0..10 {
for j in 0..10 {
let _rendered = sheet.render_range(i, j, 100, 100);
}
}
println!("range r0c0:r9c9: {:?}", sheet.render_range(0, 0, 10, 10));
for i in 0..10 {
for j in 0..10 {
sheet.write_number(i, j, format!("{}", (100 * i + j) as i32)).unwrap();
}
}
sheet.process_changes()?;
let range = sheet.range(0, 0, 10, 10);
let sum = function::sum(range.clone());
let avg = function::avg(range.clone());
let count = function::count(range.clone());
let max = function::max(range.clone());
let min = function::min(range);
println!("sum,avg,count,max,min of r0c0:r9c9: {} {} {} {} {}", sum, avg, count, max, min);
let dec = Decimal::from_str("3.1415").unwrap();
let dec2 = Decimal::from_str("18").unwrap();
let dec3 = Decimal::from_str("50.0").unwrap();
let dec4 = Decimal::new(2, 0);
let dec5 = Decimal::new(3, 0);
let dec6 = pow(dec4, dec5);
println!("decimals: {} {} {} {} {} {}", dec, dec2, dec3, dec4, dec5, dec6);
sheet.write_formula(10, 10, "=sum(r0c0:r9c9)".to_string()).unwrap();
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
sheet.write_formula(11, 10, "=avg(r0c0:r9c9)".to_string()).unwrap();
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
sheet.write_formula(12, 10, "=count(r0c0:r9c9)".to_string()).unwrap();
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
sheet.write_formula(13, 10, "=max(r0c0:r9c9)".to_string()).unwrap();
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
sheet.write_formula(14, 10, "=min(r0c0:r9c9)".to_string()).unwrap();
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
sheet.process_changes()?;
println!("changing value in (0, 0)");
sheet.write_number(0, 0, "42".into()).unwrap();
sheet.process_changes()?;
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
println!("deleting value in (0, 0)");
sheet.delete_cell(0, 0);
sheet.process_changes()?;
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
println!("changing value in (10, 10)");
sheet.delete_cell(10, 10);
sheet.process_changes()?;
println!("deleted cell: {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
Ok(())
}
fn pow(x: Decimal, y: Decimal) -> Decimal {
if y == Decimal::zero() {
return Decimal::one();
}
let temp = pow(x, (y / Decimal::new(2, 0)).trunc());
if y % Decimal::new(2, 0) == Decimal::zero() {
temp * temp
} else {
x * temp * temp
}
}
}
......@@ -129,10 +129,6 @@ impl Sheet {
}
}
// remove node from references if change was a delete
// but only if there are no other nodes that reference it right?
// otherwise a cell that is referenced could be cleared then written to
// and the thing that references it wouldn't get that data
match change {
Delete => {
let neighbors = self.references
......
#[macro_use]
extern crate pest_derive;
pub mod cell;
pub mod formula;
pub mod function;
pub mod sheet;
pub mod workbook;
use std::str::FromStr;
use anyhow::Result;
use rust_decimal::prelude::*;
use rust_decimal::Decimal;
use spreadsheet::function;
use spreadsheet::workbook::Workbook;
fn main() -> Result<()> {
let mut workbook = Workbook::new();
let sheet = workbook.add_sheet("Test".into());
println!("inserting cells");
for i in 0..200 {
for j in 0..200 {
sheet.write_text(i, j, format!("text {} {}", i, j)).unwrap();
}
}
sheet.process_changes()?;
println!("rendering ranges");
for i in 0..10 {
for j in 0..10 {
let _rendered = sheet.render_range(i, j, 100, 100);
}
}
println!("range r0c0:r3c3: {:?}", sheet.render_range(0, 0, 10, 10));
for i in 0..10 {
for j in 0..10 {
sheet.write_number(i, j, format!("{}", (100 * i + j) as i32)).unwrap();
}
}
sheet.process_changes()?;
let range = sheet.range(0, 0, 10, 10);
let sum = function::sum(range.clone());
let avg = function::avg(range.clone());
let count = function::count(range.clone());
let max = function::max(range.clone());
let min = function::min(range);
println!("sum,avg,count,max,min of r0c0:r9c9: {} {} {} {} {}", sum, avg, count, max, min);
let dec = Decimal::from_str("3.1415").unwrap();
let dec2 = Decimal::from_str("18").unwrap();
let dec3 = Decimal::from_str("50.0").unwrap();
let dec4 = Decimal::new(2, 0);
let dec5 = Decimal::new(3, 0);
let dec6 = pow(dec4, dec5);
println!("decimals: {} {} {} {} {} {}", dec, dec2, dec3, dec4, dec5, dec6);
sheet.write_formula(10, 10, "=sum(r0c0:r9c9)".to_string()).unwrap();
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
sheet.write_formula(11, 10, "=avg(r0c0:r9c9)".to_string()).unwrap();
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
sheet.write_formula(12, 10, "=count(r0c0:r9c9)".to_string()).unwrap();
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
sheet.write_formula(13, 10, "=max(r0c0:r9c9)".to_string()).unwrap();
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
sheet.write_formula(14, 10, "=min(r0c0:r9c9)".to_string()).unwrap();
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
sheet.process_changes()?;
println!("changing value in (0, 0)");
sheet.write_number(0, 0, "42".into()).unwrap();
sheet.process_changes()?;
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
println!("deleting value in (0, 0)");
sheet.delete_cell(0, 0);
sheet.process_changes()?;
println!("sum(r10c10:r10c10): {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
println!("changing value in (10, 10)");
sheet.delete_cell(10, 10);
sheet.process_changes()?;
println!("deleted cell: {:?}", sheet.render_range(10, 10, 1, 1));
println!("avg(r10c10:r10c10): {:?}", sheet.render_range(11, 10, 1, 1));
println!("count(r10c10:r10c10): {:?}", sheet.render_range(12, 10, 1, 1));
println!("max(r10c10:r10c10): {:?}", sheet.render_range(13, 10, 1, 1));
println!("min(r10c10:r10c10): {:?}", sheet.render_range(14, 10, 1, 1));
Ok(())
}
fn pow(x: Decimal, y: Decimal) -> Decimal {
if y == Decimal::zero() {
return Decimal::one();
}
let temp = pow(x, (y / Decimal::new(2, 0)).trunc());
if y % Decimal::new(2, 0) == Decimal::zero() {
temp * temp
} else {
x * temp * temp
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment