반응형

💻코드

<div id="canvas-realtile-graph"><svg width="355" height="110"></svg></div>
<script> 	
			var n = 60;
			var dataGal=[];
		    //random = d3.randomNormal(0, .2),
		    //dataGal = [0.3639, 0.4862, 0.7588, 0.5905, 0.3522, 0.8548, 0.1268, 0.9583, 0.1176, 0.1361, 0.8377, 0.4384, 0.5754, 0.7842, 0.9094, 0.7698, 0.1691, 0.0518, 0.8581];
		    //dataGal = [5,10,15,20,25,30,35,40];
/* 			dataGal = [ 
							  { "x": 1558583546*1000,   "y": 0.3639},  
							  { "x": 1558583547*1000,  "y": 0.4862},
							  { "x": 1558583548*1000,  "y": 0.7588}, 
							  { "x": 1558583549*1000,  "y": 0.5905},
							  { "x": 1558583550*1000,  "y": 0.8548},  
							  { "x": 1558583551*1000, "y": 0.9583}
							]; */
			
			var svg = d3.select("svg"),
			    margin = {top: 20, right: 20, bottom: 20, left: 40},
			    width = +svg.attr("width") - margin.left - margin.right,
			    height = +svg.attr("height") - margin.top - margin.bottom,
			    g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
			
			
			var abcd3 = (1558583546+60)*1000;
			var abcd2 = 1558583546*1000;
			
			var x = d3.scaleTime()
			    .domain([abcd2, abcd3])
			    .range([0, width]);
			
			var y = d3.scaleLinear()
			    .domain([0, 1])
			    .range([height, 0]);
			
			var line = d3.line()
			    .x(function(d) { return x(d.x); })
			    .y(function(d) { return y(d.y); });
			
			g.append("defs").append("clipPath")
			    .attr("id", "clip")
			  .append("rect")
			    .attr("width", width)
			    .attr("height", height);
			
			g.append("g")
			    .attr("class", "axis axis--x")
			    .attr("transform", "translate(0," + y(0) + ")")
			    .call(d3.axisBottom(x).ticks(3).tickFormat(d3.timeFormat("%M:%S")));
			
			g.append("g")
			    .attr("class", "axis axis--y")
			    .call(d3.axisLeft(y).ticks(5));
			
			g.append("g")
			    .attr("clip-path", "url(#clip)")
			  .append("path")
			    .datum(dataGal)
			    .attr("class", "line")
			  .transition()
			    .duration(1000)
			    .ease(d3.easeLinear)
			    .on("start", tick);
			
 			function tick() {
 				console.log("tick 조회")
			  /*var gal = { "x": 1558583552*1000, "y": 0.2590};*/
			  var gal = { "x": new Date().getTime(), "y": Math.floor(Math.random()*10000)/10000};
 				
			  dataGal.push(gal);
			  rescale();
			  
			  // Redraw the line.
			  d3.select(this)
			      .attr("d", line)
			      .attr("transform", null);

			  d3.active(this)
			      //.attr("transform", "translate(" + x(-1) + ",0)")
			    .transition()
			    .on("start", tick);

			  if(dataGal.length>=60){
				  dataGal.shift();
			  } 
			} 
			
			
			function rescale() {
			    
			    y.domain([0,1.0]);  // 스케일 바꾸기
			    x.domain([new Date().getTime()-60000,new Date().getTime()]);
			    
			    g.select(".axis--y").remove(); //스케일 라벨 지우기
			    g.select(".axis--x").remove(); 
				
			    g.append("g")
			    .attr("class", "axis axis--y")
			    .call(d3.axisLeft(y).ticks(6)); //스케일 라벨 그리기
			    
				g.append("g")
			    .attr("class", "axis axis--x")
			    .attr("transform", "translate(0," + y(0) + ")")
			    .call(d3.axisBottom(x).ticks(3).tickFormat(d3.timeFormat("%M:%S")));
			
			}
			
			
			
			function ParseToDate(d){
				return d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			}

</script>
반응형
반응형

📢 [JAVA] 리터럴과 형변환

📋 상수와 리터럴

▼ 상수 (constant) : 변하지 않는 수 (ex : final 등으로 사용)

▼ 리터럴 (literal) : 프로그램에서 사용하는 모든 숫자,값,논리 값 (ex : 숫자,10,3.14,true,'a')

모든 리터럴은 상수 풀 (constant pool)에 저장되어 있음

상수풀에 저장될 때 정수는 int (4byte) , 실수는 double (8byte) 로 저장됨.

12,345,678,900L 이렇게 큰 숫자의 경우 L 을 붙여 8바이트로 처리됨

위의 각 숫자들이 상수풀에 저장되어있다가 프로그래밍을 할때 바로 꺼내와서 사용

 

📋 형변환

▼ 서로 다른 자료형의 값이 대입되는 경우 형 변환이 일어남

묵시적 형 변환 (implicit type conversion):

 작은수에서 큰 수로 덜 정밀한 수에서 더 정밀한 수로 대입되는 경우

명시적 형 변환 (explicit type conversion) :

 변환 되는 자료 형을 명시 자료의 손실이 발생 할 수 있음

묵시적 형 변환의 경우 별다른 코딩은 안해도 되고 명시적 형변환의 경우 캐스팅을 해줘야함

💻코드1

byte bNum = 10;
int iNum = bNum; 
// byte 는 1바이트 int 는 4바이트 따라서 묵시적 형변환

System.out.println(bNum); //10
System.out.println(iNum); //10

int iNum2 = 2;
float fNum = iNum2; 
// 정수형보다 실수형이 더 크기떄문에 별도의 캐스팅없이 묵시적 형변환

System.out.println(fNum); //20.0

double dNum;
dNum = fNum + iNum;
//fNum은 float 형이기 때문에 iNum 은 float 형식으로 형변환 1번
//dNum (double형)으로 값을 넣어주기 떄문에 fNum , iNum  (double)형으로 형변환 2번
System.out.println(dNum); //30.0




int iNum = 1000; 
byte bNum = (byte) il
System.out.println(bNum); //-24
// byte는 2의-7승(-127) ~ 2의 7승(127) 까지 표현하기 때문에
// iNum의 데이터가 손실이 된다. 명시적 형변환

double dNum = 1.2;
float fNum = 0.9F; 

int iNum1 = (int)dNum1 + (int)fNum;
int iNum2 = (int)(dNum1 + fNum);
System.out.println(iNum1); //1
System.out.println(iNum2); //2
// 실수를 int로 형변환 하면 소수점이하 자리는 버림이 된다.
// 따라서 iNum1 은 1+0 이고 iNum2 는 2.1 에서 소수점을 버리게 된다.

📋 진법 변환

▼2진수 , 8진수 , 16진수 를 각 진법으로 쓰면

2진수 0b~~~ (ex: 0b1010)

8진수 0~~~~ (ex: 012)

16진수 0x~~~~ (ex: 0xA)

(대문자 소문자는 가리지 않습니다.)

💻코드2

int num = 10; 
int bnum = 0b1010;
int onum = 012;
int xnum = 0xA;

System.out.println(num ); //10
System.out.println(bnum ); //10
System.out.println(onum ); //10
System.out.println(xnum ); //10

위처럼 진법변환을 프로그래밍 코딩을 할수 있다.
 
반응형

'프로그래밍 > Java' 카테고리의 다른 글

JAVA - 인스턴스, 힙 메모리  (1) 2022.01.01
Java - 라운드 로빈 (Round Robin) 예제  (0) 2019.05.29
반응형

◎ 객체

▼ 객체 지향 프로그램의 대상 , 생성된 인스턴스

◎ 클래스

▼ 객체를 프로그래밍 하기위해 코드로 만든 상태

◎ 인스턴스

▼ 클래스가 메모리에 생성된 상태

◎ 멤버 변수

▼ 클래스의 속성, 특성

◎ 메서드

▼ 멤버 변수를 이용하여 클래스의 기능을 구현

◎ 참조변수

▼ 메모리에 생성된 인스턴스를 가리키는 변수

◎ 참조 값

▼ 생성된 인스턴스의 메모리 주소값

StudentTest.java 에서
Student studentLee = new Student();  // 인스턴스 : 생성과 동시에 자바 heap memory에 할당
//studentLee 는 참조변수이다 student.java의 인스턴스를 참조하고 있기 때문이다.
System.out.println(studentLee);
//이렇게 studentLee 를 출력하면 student.java의 참조값이 출력된다
//(ex: classpart.Student@a23d95)

Student.java 에서
 public int studentID;
 public String studentName;
 public String address;
//위 변수들을 멤버변수라고 한다

 public void showStudentInfo(){
}
//위의 것을 student.java 클래스의 메서드 라고 한다.

◎ Stack

▼ main에 작성한 변수등등 코드들은 stack 에 차례대로 쌓엿다가 제 할 일을 다하면 다시 없어지는 그런 구조이다. 먼저 작성한 변수들이 차례대로 쌓엿다가 젤 나중에 쌓인 애들이 먼저 없어지는 그런....(선입후출)

◎ HeapMemory

▼ JVM (자바 버츄얼 머신)이 가지고있는 가상 메모리이다. 인스턴스들이 쌓이져 주로 NEW 생성자를 사용하면 Heap memory에 쌓인다. 하지만 메서드 들은 heammemory 가 아닌 다른 곳에 있다.

◎ 그림 설명

▼ main 에서 Student studentLee = new student(); 를 하였을경우

student.java의 student 인스턴스가 heap 메모리에 적재되고

studentLee 는 heap 메모리에 적재된 student 인스턴스를 가르키고있는 참조 변수가된다.

하여 student.java의 멤버변수들을 studentLee.studentId 등으로 호출을 할 수 있는것이다.

studentKim 도 똑같다.

◎ 가비지콜렉션

▼ 자바에는 가바지콜렉션이라고 복잡한 알고리즘으로 쌓인 클래스가있는데 이놈이 주기적으로 HEAP MEMORY에 적재된 놈들을 사용하지않으면 다시 메모리를 반환하는 그런 편리한 역할을 한다. 이건 자바의 장점이다 C나 C++에는 없는..

◎ 변수의 생성과 메모리

반응형

'프로그래밍 > Java' 카테고리의 다른 글

[JAVA] 리터럴과 형변환  (0) 2022.01.04
Java - 라운드 로빈 (Round Robin) 예제  (0) 2019.05.29
반응형



▼ 환경

eGovFrame 3.1 (전자정부프레임워크버전)

spring 3.2.9 release

egov 3.0.0 version

mod-socket-io 1.0.2 < -- 이건 머하는놈인질 모르겟음

◎ XML 설정

▼ 내용

먼저 전자정부에는 context-transaction.xml 이란 xml 파일이 있을꺼다 여기에 tx:advice 와 aop를 설정해주면 된다 .



context-transaction.xml

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" rollback-for="Exception"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="requiredTx" expression="execution(* org.egovframework.karico..impl.*Impl.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="requiredTx" /> </aop:config> </beans>

◎ JAVA에 작성하기

▼ 내용

XML을 설정하였으면 트랜잭션을 걸 메소드에 아래와 같이 작성하면된다.

본인은 컨트롤러에 작성하였다 컨트롤러 안에는 INSERT문을 실행하는 SERVICE들이 한 4~5개 된다. 만약 아래의 commit 나 rollback 를 안써놓으면 그냥 트랜잭션이 잡혀있는상태로 된다.

톰캣을끄면 그트랜잭션은 사라지고 rollback 되는거같더라.

어쩃든 이렇게 작성해놓으면 commit이나 rollback 둘중 하나가 되기 전까지 디비에 써지진 않는다.

RESTfullReportController.java

@Controller public class RESTfullReportController { @Resource(name = "txManager") protected DataSourceTransactionManager txManager; @RequestMapping("/api/saveInitialCheckReport") public ModelAndView saveInitialCheckReport (HttpServletRequest request, HttpServletResponse response) throws Exception { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus txStatus = txManager.getTransaction(def); try { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ 각종 INSERT UPDATE 등 DB 문 ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ txManager.commit(txStatus); //정상일경우 COMMIT; model.put("result", 0); } catch (Exception e) { e.printStackTrace(); txManager.rollback(txStatus); //에러날경우 CATCH로 빠져서 ROLLBACK; model.put("result", -1); } }


◎ 위에처럼만 하면 끝 생각보다 쉽다..


반응형
반응형


Spring - 프로젝트 한글깨짐 설정


◎ 이클립스 UTF-8 설정

STS(스프링) 에서 한글이 깨지는 이유는 기본 인코딩이 MS949로 되어 있어서 한글이 깨진다.

인코딩을 모두 UTF-8로 변경을 해주어야 한글이 깨지지 않는다.

먼저 Window - Preferences 로 들어가준다.


CSS, HTML, JSP 항목에서 Encoding 항목을 ISO 10646/Unicode(UTF-8)로 변경해 준다.


General -> Workspace의 Text file encoiding 을 UTF-8로 바꿔준다.


◎ 이클립스 웹브라우저 설정

▼ General -> Web Brower에서 New를 누른후 Chrome을 설정한다.


◎ XML UTF-8 설정

▼프로젝트내 web.xml 안에 아래 내용 추가

<web-app> 태그 안에 Servlet-mapping 태그 밑에 추가하면된다

<!-- 한글깨짐 방지 --> <!-- filter와 filter-mapping을 만들어 준다. --> <filter> <!-- filter안에는 filter-name, filter-class, init-param을 추가해 준다. filter-name은 원하는대로 지정해도됨 --> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <!-- encoidng값을 UTF-8로 만들어 준다. --> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

◎ JSP UTF-8 설정

▼ 맨위 <%@ UTF-8 설정과 META 태그의 UTF-8 설정을 해주면된다.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page session="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Home</title> </head> <body> <h1> Hello world! </h1> <P> The time on the server is ${serverTime}. </P> </body> </html>


반응형

+ Recent posts